VirtualBox

Changeset 102985 in vbox for trunk/src/VBox/Runtime/testcase


Ignore:
Timestamp:
Jan 22, 2024 9:59:41 AM (13 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
161217
Message:

tstRTStrFormat: Added an overflow test.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/testcase/tstRTStrFormat.cpp

    r98103 r102985  
    302302                      "expected: '%s'\n",
    303303                      pszBuf, szCorrect);
     304
     305    /* overflow */
     306    size_t const cbOverflowBuf = 40;
     307    static char const s_szOverflowExpect[] = "i=8                                    ";
     308    char *pszBuf3 = (char *)RTTestGuardedAllocTail(hTest, cbOverflowBuf);
     309    cch = RTStrPrintf(pszBuf3, cbOverflowBuf, "i=%d%*s\n", (int)8, cbOverflowBuf, "");
     310    if (strcmp(pszBuf3, s_szOverflowExpect))
     311        RTTestIFailed("error: '%s' (#2)\n"
     312                      "wanted '%s' (#2)\n", pszBuf, s_szOverflowExpect);
     313    else if (cch != sizeof(s_szOverflowExpect) - 1)
     314        RTTestIFailed("error: got %zd, expected %zd (#2)\n", cch2, sizeof(s_szOverflowExpect) - 1);
     315    RTTestGuardedFree(hTest, pszBuf3);
    304316}
    305317
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