[Libreoffice] [PATCH] Refactor to make cppcheck happy
michael.meeks at novell.com
Wed Sep 29 13:02:48 PDT 2010
On Wed, 2010-09-29 at 11:48 -0700, Justin Malcolm wrote:
> From the 'easy hacks' page it seemed that getting rid of warnings and
> flags by tools like cppcheck was a goal.
Sure ! of course :-)
> Attached is a small patch that does nothing except eliminate one
> cppcheck warning. It is contributed under the LGPL3+.
What is the warning ? :-)
> As I said, it does nothing different and, depending on the compiler,
> it could even be less efficient. It does however make cppcheck happy.
> Is this kind of thing useful?
Certainly; clearly it'd be more re-assuring if it was compiled & ran
xrealloc(void *ptr, size_t size)
- ptr = realloc(ptr, size);
+ void *newptr = realloc(ptr, size);
- if ( !ptr )
+ if (!newptr)
+ ptr = newptr;
err_quit("out of memory");
So for size > 0 - realloc will return a non-NULL (perhaps different)
pointer. So - if (!newptr) [ ie. if (newptr == NULL) ] will never
succeed - surely ?
michael.meeks at novell.com <><, Pseudo Engineer, itinerant idiot
More information about the LibreOffice