VirtualBox

Changeset 63122 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Aug 7, 2016 3:25:21 AM (8 years ago)
Author:
vboxsync
Message:

vboxClipboardDump,DumpHtml: Warnings (always check that the for loop counter and limit are somewhat compative). RTStrCopy will always terminate the result, so give it the full size so it won't truncate a string that's missing the terminator.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxClipboard-win.cpp

    r63121 r63122  
    9999
    100100            //size_t cb = RTStrNLen(pv, );
    101             char *buf = (char *)RTMemAlloc(cb + 1);
    102             RT_BZERO(buf, cb);
    103             RTStrCopy(buf, cb, (const char*)pv);
     101            char *pszBuf = (char *)RTMemAllocZ(cb + 1);
     102            RTStrCopy(pszBuf, cb + 1, (const char *)pv);
    104103            for (size_t off = 0; off < cb; ++off)
    105104            {
    106                 if (buf[off] == '\n' || buf[off] == '\r')
    107                     buf[off] = ' ';
    108             }
    109 
    110             Log(("%s\n", buf));
    111             RTMemFree(buf);
     105                if (pszBuf[off] == '\n' || pszBuf[off] == '\r')
     106                    pszBuf[off] = ' ';
     107            }
     108
     109            Log(("%s\n", pszBuf));
     110            RTMemFree(pszBuf);
    112111        }
    113112        else
     
    834833}
    835834
    836 int DumpHtml(char* src, size_t cb)
    837 {
    838     size_t lenght = 0;
    839     int rc = RTStrNLenEx(src, cb, &lenght);
     835int DumpHtml(const char *pszSrc, size_t cb)
     836{
     837    size_t cchIgnored = 0;
     838    int rc = RTStrNLenEx(pszSrc, cb, &cchIgnored);
    840839    if (RT_SUCCESS(rc))
    841840    {
    842         char* buf = (char*)RTMemAlloc(cb + 1);
    843         if (buf != NULL)
    844         {
    845             RT_BZERO(buf, cb + 1);
    846             rc = RTStrCopy(buf, cb, (const char*)src);
     841        char *pszBuf = (char *)RTMemAllocZ(cb + 1);
     842        if (pszBuf != NULL)
     843        {
     844            rc = RTStrCopy(pszBuf, cb + 1, (const char *)pszSrc);
    847845            if (RT_SUCCESS(rc))
    848846            {
    849847                for (size_t i = 0; i < cb; ++i)
    850                     if (buf[i] == '\n' || buf[i] == '\r')
    851                         buf[i] = ' ';
     848                    if (pszBuf[i] == '\n' || pszBuf[i] == '\r')
     849                        pszBuf[i] = ' ';
    852850            }
    853851            else
    854852                Log(("Error in copying string.\n"));
    855             Log(("Removed \\r\\n: %s\n", buf));
    856             RTMemFree(buf);
     853            Log(("Removed \\r\\n: %s\n", pszBuf));
     854            RTMemFree(pszBuf);
    857855        }
    858856        else
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