Date: prev next · Thread: first prev next last
2010 Archives by date, by thread · List index


On Sat, 2010-10-30 at 17:26 +0200, Gert Faller wrote:
Hi,

The two cppcheck warnings in 'libs-core' about 'realloc'.
Not sure about that : what to do on NULL ?

There are others, for example in :
'sdk/odk/source/unoapploader/unx/unoapploader.c'
but with 'exit(EXIT_FAILURE)' on NULL.

Hmm, well in C land this kind of thing would fit the bill and silence
cppcheck....

newthing = realloc(oldthing....)
if (newthing == NULL)
{
    free(oldthing)
    exit(EXIT_FAILURE);
}
oldthing = newthing;

So for the unoapploader.c if you cook up something like the above and
send it in I'll apply that given that its already exiting on failure and
its good to clear the cppcheck warnings in order to see when new ones
appear.

For the C++ code however, we don't have to grovel around with realloc,
like you say, what to do on NULL, and its non-trivial to deal with it.
So I suggest replacing them with std::vectors, e.g. in the xfld_attr.cxx
example you could try and change the "Attribute *mpList" to a
std::vector<Attribute> maList; and make the corresponding changes, e.g.
maList.resize(mnSize) instead of the mpList = realloc(mnSize * ...);
That would be the ideal solution in my mind.

C.


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.