[Libreoffice] [PATCH] cppcheck "Common realloc mistake"

Gert Faller gertfaller at aliceadsl.fr
Sun Oct 31 12:51:39 PDT 2010


a second try.
Making cppcheck happy is not easy...

The first file may be ok.

The second no : but what to do ? loose memory or risk a fail ?
        /* very strange case, but have to believe it: reduce the
         * full qualified name to the unqualified host name */
        if ( !bHostsAreEqual )
            OSL_TRACE("_osl_getFullQualifiedDomainName: "
                      "suspect FQDN: %s\n", pFullQualifiedName);

            pFullQualifiedName[ nLengthOfHostName ] = '\0';
            pFullQualifiedName = (sal_Char*)realloc ( pFullQualifiedName,
                                (nLengthOfHostName + 1) * sizeof( sal_Char ));
    /* always return a hostname looked up as carefully as possible
     * this string must be freed by the caller */

And in "ure/sal/osl/w32/security.c"

            DWORD  nInfoBuffer = 512;
            UCHAR* pInfoBuffer = malloc(nInfoBuffer);

            while (!GetTokenInformation(hAccessToken, TokenUser,
                                           pInfoBuffer, nInfoBuffer,
                if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
                    pInfoBuffer = realloc(pInfoBuffer, nInfoBuffer);
                    pInfoBuffer = NULL;
I'm dumb...

And that was the C side... Let's try C++...

-------------- next part --------------
A non-text attachment was scrubbed...
Name: realloc_patch_1.patch
Type: application/octet-stream
Size: 2082 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20101031/48e45519/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: realloc_patch_2.patch
Type: application/octet-stream
Size: 1402 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20101031/48e45519/attachment-0001.obj>

More information about the LibreOffice mailing list