Cppcheck - HTML report - digiKam-nl-search-more-criteria-rev-e2466e0973

# Cppcheck report - digiKam-nl-search-more-criteria-rev-e2466e0973: ../../core/libs/dimg/dimg_data.cpp

      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    /* ============================================================
     *
     * This file is a part of digiKam project
     * https://www.digikam.org
     *
     * Date        : 2005-06-14
     * Description : digiKam 8/16 bits image management API.
     *               Data management.
     *
     * SPDX-FileCopyrightText: 2005-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
     * SPDX-FileCopyrightText: 2006-2013 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
     *
     * SPDX-License-Identifier: GPL-2.0-or-later
     *
     * ============================================================ */

    #include "dimg_p.h"

    namespace Digikam
    {

    DImg& DImg::operator=(const DImg& image)
    {
        m_priv = image.m_priv;

        return *this;
    }

    bool DImg::operator==(const DImg& image) const
    {
        return (m_priv == image.m_priv);
    }

    void DImg::reset()
    {
        m_priv = new Private;
    }

    void DImg::detach()
    {
        // are we being shared?

        if (m_priv->ref == 1)
        {
            return;
        }

        QExplicitlySharedDataPointer<Private> old(m_priv);

        m_priv = new Private;
        copyImageData(old);
        copyMetaData(old);

        if (old->data)
        {
            size_t bsize = allocateData();
            memcpy(m_priv->data, old->data, bsize);
        }
    }

    void DImg::putImageData(uint width, uint height, bool sixteenBit, bool alpha, uchar* const data, bool copyData)<--- Shadow argument<--- Shadow argument<--- Shadow argument
    {
        // set image data, metadata is untouched

        bool null = (width == 0) || (height == 0);

        // allocateData, or code below will set null to false

        setImageData(true, width, height, sixteenBit, alpha);

        // replace data

        delete [] m_priv->data;
        m_priv->data = nullptr;

        if (null)
        {
            // image is null - no data

            return;
        }
        else if (copyData)
        {
            size_t bsize = allocateData();

            // cppcheck-suppress knownConditionTrueFalse
            if (m_priv->data && data)
            {
                memcpy(m_priv->data, data, bsize);
            }
        }
        else
        {
            if (data)
            {
                m_priv->data = data;
                m_priv->null = false;
            }
            else
            {
                allocateData();
            }
        }
    }

    void DImg::putImageData(uchar* const data, bool copyData)
    {
        if      (!data)
        {
            delete [] m_priv->data;
            m_priv->data = nullptr;
            m_priv->null = true;
        }
        else if (copyData)
        {
            memcpy(m_priv->data, data, numBytes());
        }
        else
        {
            m_priv->data = data;
        }
    }

    void DImg::resetMetaData()
    {
        m_priv->attributes.clear();
        m_priv->embeddedText.clear();
        m_priv->metaData = MetaEngineData();
    }

    uchar* DImg::stripImageData()
    {
        uchar* const data  = m_priv->data;
        m_priv->data       = nullptr;
        m_priv->null       = true;

        return data;
    }

    void DImg::copyMetaData(const QExplicitlySharedDataPointer<Private>& src)
    {
        m_priv->metaData     = src->metaData;
        m_priv->attributes   = src->attributes;
        m_priv->embeddedText = src->embeddedText;
        m_priv->iccProfile   = src->iccProfile;
        m_priv->imageHistory = src->imageHistory;

        // FIXME: what about sharing and deleting lanczos_func?
    }

    void DImg::copyImageData(const QExplicitlySharedDataPointer<Private>& src)
    {
        setImageData(src->null, src->width, src->height, src->sixteenBit, src->alpha);
    }

    size_t DImg::allocateData() const
    {
        quint64 bsize = (quint64)m_priv->width  *
                        (quint64)m_priv->height *
                        (quint64)(m_priv->sixteenBit ? 8 : 4);

        if (bsize >= std::numeric_limits<size_t>::max())
        {
            m_priv->null = true;

            return 0;
        }

        m_priv->data = DImgLoader::new_failureTolerant(bsize);

        if (!m_priv->data)
        {
            m_priv->null = true;

            return 0;
        }

        m_priv->null = false;

        return bsize;
    }

    void DImg::setImageDimension(uint width, uint height)<--- Shadow argument<--- Shadow argument
    {
        m_priv->width  = width;
        m_priv->height = height;
    }

    void DImg::setImageData(bool null, uint width, uint height, bool sixteenBit, bool alpha)<--- Shadow argument<--- Shadow argument<--- Shadow argument
    {
        m_priv->null       = null;
        m_priv->width      = width;
        m_priv->height     = height;
        m_priv->alpha      = alpha;
        m_priv->sixteenBit = sixteenBit;
    }

    } // namespace Digikam