VirtualBox

Changeset 51833 in vbox


Ignore:
Timestamp:
Jul 3, 2014 7:20:56 AM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
94681
Message:

xpcom18a4: upstream fix

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/nsprpub/pr/src/io/prprf.c

    r21149 r51833  
    331331** form.
    332332**
    333 ** XXX stop using sprintf to convert floating point
     333** XXX stop using snprintf to convert floating point
    334334*/
    335335static int cvt_f(SprintfState *ss, double d, const char *fmt0, const char *fmt1)
     
    339339    int amount = fmt1 - fmt0;
    340340
    341     PR_ASSERT((amount > 0) && (amount < sizeof(fin)));
    342     if (amount >= sizeof(fin)) {
    343         /* Totally bogus % command to sprintf. Just ignore it */
     341    if (amount <= 0 || amount >= sizeof(fin)) {
     342        /* Totally bogus % command to snprintf. Just ignore it */
    344343        return 0;
    345344    }
     
    347346    fin[amount] = 0;
    348347
    349     /* Convert floating point using the native sprintf code */
     348    /* Convert floating point using the native snprintf code */
    350349#ifdef DEBUG
    351350    {
     
    357356    }
    358357#endif
    359     sprintf(fout, fin, d);
    360 
    361     /*
    362     ** This assert will catch overflow's of fout, when building with
    363     ** debugging on. At least this way we can track down the evil piece
    364     ** of calling code and fix it!
    365     */
    366     PR_ASSERT(strlen(fout) < sizeof(fout));
     358    memset(fout, 0, sizeof(fout));
     359    snprintf(fout, sizeof(fout), fin, d);
     360    /* Explicitly null-terminate fout because on Windows snprintf doesn't
     361     * append a null-terminator if the buffer is too small. */
     362    fout[sizeof(fout) - 1] = '\0';
    367363
    368364    return (*ss->stuff)(ss, fout, strlen(fout));
Note: See TracChangeset for help on using the changeset viewer.

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