VirtualBox

Ignore:
Timestamp:
Feb 21, 2012 12:04:21 AM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
76350
Message:

RTStrFormatNumber: Assert some buffer sanity.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/string/strformat.cpp

    r38659 r40186  
    148148 * @param     fFlags         Flags (NTFS_*).
    149149 */
    150 RTDECL(int) RTStrFormatNumber(char *psz, uint64_t u64Value, unsigned int uiBase, signed int cchWidth, signed int cchPrecision, unsigned int fFlags)
     150RTDECL(int) RTStrFormatNumber(char *psz, uint64_t u64Value, unsigned int uiBase, signed int cchWidth, signed int cchPrecision,
     151                              unsigned int fFlags)
    151152{
    152153    return rtStrFormatNumber(psz, *(KSIZE64 *)(void *)&u64Value, uiBase, cchWidth, cchPrecision, fFlags);
     
    167168 * @param     fFlags         Flags (NTFS_*).
    168169 */
    169 static int rtStrFormatNumber(char *psz, KSIZE64 ullValue, unsigned int uiBase, signed int cchWidth, signed int cchPrecision, unsigned int fFlags)
     170static int rtStrFormatNumber(char *psz, KSIZE64 ullValue, unsigned int uiBase, signed int cchWidth, signed int cchPrecision,
     171                             unsigned int fFlags)
    170172{
    171173    const char     *pachDigits = "0123456789abcdef";
    172174    char           *pszStart = psz;
     175    int             cchMax;
    173176    int             cchValue;
    174177    unsigned long   ul;
     
    251254     * width - only if ZEROPAD
    252255     */
     256    cchMax    = 64 - (cchValue + i + 1);   /* HACK! 64 bytes seems to be the usual buffer size... */
    253257    cchWidth -= i + cchValue;
    254258    if (fFlags & RTSTR_F_ZEROPAD)
    255         while (--cchWidth >= 0)
     259        while (--cchWidth >= 0 && i < cchMax)
    256260        {
     261            AssertBreak(i < cchMax);
    257262            psz[i++] = '0';
    258263            cchPrecision--;
     
    260265    else if (!(fFlags & RTSTR_F_LEFT) && cchWidth > 0)
    261266    {
    262         for (j = i-1; j >= 0; j--)
     267        AssertStmt(cchWidth < cchMax, cchWidth = cchMax - 1);
     268        for (j = i - 1; j >= 0; j--)
    263269            psz[cchWidth + j] = psz[j];
    264270        for (j = 0; j < cchWidth; j++)
     
    266272        i += cchWidth;
    267273    }
    268     psz += i;
    269 
    270274
    271275    /*
     
    273277     */
    274278    while (--cchPrecision >= cchValue)
    275         *psz++ = '0';
     279    {
     280        AssertBreak(i < cchMax);
     281        psz[i++] = '0';
     282    }
     283
     284    psz += i;
    276285
    277286    /*
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