VirtualBox

Changeset 85212 in vbox


Ignore:
Timestamp:
Jul 11, 2020 12:27:52 PM (5 years ago)
Author:
vboxsync
Message:

Main/QMTranslatorImpl.cpp: Sign conversion issues with Clang 11. Fixed seek() to stop at m_end. Some doxgyen conversion and likely mojo. bugref:9790

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-all/QMTranslatorImpl.cpp

    r83794 r85212  
    2828
    2929/* QM File Magic Number */
    30 static const size_t MagicLength = 16;
    31 static const uint8_t Magic[MagicLength] =
     30static const size_t g_cbMagic = 16;
     31static const uint8_t g_abMagic[g_cbMagic] =
    3232{
    3333    0x3c, 0xb8, 0x64, 0x18, 0xca, 0xef, 0x9c, 0x95,
     
    6060public:
    6161
    62     QMBytesStream(const uint8_t *const dataStart, size_t cbSize) :
    63         m_cbSize(dataStart ? cbSize : 0),
    64         m_dataStart(dataStart),
    65         m_iter(dataStart)
     62    QMBytesStream(const uint8_t *const dataStart, size_t cbSize)
     63        : m_cbSize(dataStart ? cbSize : 0)
     64        , m_dataStart(dataStart)
     65        , m_iter(dataStart)
    6666    {
    6767        setEnd();
    6868    }
    6969
    70     /* Sets end pointer
     70    /** Sets end pointer.
    7171     * Used in message reader to detect the end of message block */
    7272    inline void setEnd(size_t pos = 0)
     
    8989    }
    9090
    91     /* Reads string in UTF16 and converts it into a UTF8 string */
     91    /** Reads string in UTF16 and converts it into a UTF8 string */
    9292    inline com::Utf8Str readUtf16String()
    9393    {
     
    109109    }
    110110
    111     /* Reads string in one-byte encoding
     111    /** Reads string in one-byte encoding.
    112112     * The string is assumed to be in ISO-8859-1 encoding */
    113113    inline com::Utf8Str readString()
     
    120120    }
    121121
    122     /* Checks the magic number
    123      * Should be called when in the beginning of the data */
     122    /** Checks the magic number.
     123     * Should be called when in the beginning of the data
     124     * @throws exception on mismatch  */
    124125    inline void checkMagic()
    125126    {
    126         checkSize(MagicLength);
    127         if (memcmp(&(*m_iter), Magic, MagicLength)) throw QMException("Wrong magic number");
    128         m_iter += MagicLength;
    129     }
    130 
    131     /* Has we reached the end pointer? */
    132     inline bool hasFinished() { return m_iter == m_end; }
    133 
    134     /* Returns current stream position */
    135     inline size_t tellPos() { return m_iter - m_dataStart; }
    136 
    137     /* Moves current pointer to a desired position */
    138     inline void seek(int pos) { m_iter += pos; }
    139 
    140     /* Checks whether stream has enough data to read size bytes */
    141     inline void checkSize(int size)
    142     {
    143         if (m_end - m_iter < size) throw QMException("Incorrect item size");
     127        checkSize(g_cbMagic);
     128        if (RT_LIKELY(memcmp(&(*m_iter), g_abMagic, g_cbMagic) == 0))
     129            m_iter += g_cbMagic;
     130        else
     131            throw QMException("Wrong magic number");
     132    }
     133
     134    /** Has we reached the end pointer? */
     135    inline bool hasFinished()
     136    {
     137        return m_iter == m_end;
     138    }
     139
     140    /** Returns current stream position */
     141    inline size_t tellPos()
     142    {
     143        return (size_t)(m_iter - m_dataStart);
     144    }
     145
     146    /** Moves current pointer to a desired position */
     147    inline void seek(uint32_t offSkip)
     148    {
     149        size_t cbLeft = (size_t)(m_end - m_iter);
     150        if (cbLeft <= offSkip)
     151            m_iter += offSkip;
     152        else
     153            m_iter = m_end; /** @todo r=bird: Or throw exception via checkSize? */
     154    }
     155
     156    /** Checks whether stream has enough data to read size bytes */
     157    inline void checkSize(size_t size)
     158    {
     159        if (RT_LIKELY((size_t)(m_end - m_iter) >= size))
     160            return;
     161        throw QMException("Incorrect item size");
    144162    }
    145163};
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette