RSS/Atom feed Twitter
Site is read-only, email is disabled

Patch for cppcheck error "Common realloc mistake"

This discussion is connected to the gimp-developer-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

3 of 3 messages available
Toggle history

Please log in to manage your subscriptions.

Patch for cppcheck error "Common realloc mistake" Julien 27 Oct 15:48
  Patch for cppcheck error "Common realloc mistake" Mukund Sivaraman 27 Oct 16:27
   Patch for cppcheck error "Common realloc mistake" Julien Nabet 27 Oct 17:47
Julien
2011-10-27 15:48:23 UTC (about 13 years ago)

Patch for cppcheck error "Common realloc mistake"

Hello,

I had sent a simple proposed patch 21/08 (http://old.nabble.com/Patch-for-cppcheck-error-%22Common-realloc-mistake%22-to32305733.html)

Since I didn't get answers and I received an email about gimp-dev mailing list available, I wanted to propose this very simple patch again :

diff --git a/libgimpbase/gimpreloc.c b/libgimpbase/gimpreloc.c index 7461bed..238797f 100644
--- a/libgimpbase/gimpreloc.c
+++ b/libgimpbase/gimpreloc.c
@@ -245,7 +245,7 @@ _br_find_exe_for_symbol (const void *symbol, GimpBinrelocInitError *error)
* then transform that into a pointer. */ if (address_string_len < len + 3) { address_string_len = len + 3; - address_string = (char *) g_try_realloc (address_string, address_string_len); + address_string = (char *) g_realloc (address_string, address_string_len); }

memcpy (address_string, "0x", 2);

Julien.

PS : is there a Nabble interface for this mailing-list ?

Mukund Sivaraman
2011-10-27 16:27:51 UTC (about 13 years ago)

Patch for cppcheck error "Common realloc mistake"

Hi Julien

On Thu, Oct 27, 2011 at 05:48:23PM +0200, Julien wrote:

Hello,

I had sent a simple proposed patch 21/08 (http://old.nabble.com/Patch-for-cppcheck-error-%22Common-realloc-mistake%22-to32305733.html)

[snip]

if (address_string_len < len + 3) { address_string_len = len + 3; - address_string = (char *) g_try_realloc (address_string, address_string_len); + address_string = (char *) g_realloc (address_string, address_string_len); }

memcpy (address_string, "0x", 2);

If address_string is NULL as returned by g_try_realloc(), the following memcpy() would cause the process to segfault, perhaps creating a core.

With your patch, it abort()s _if_ the underlying realloc() returns NULL. But you better read Documentation/vm/overcommit-accounting in a Linux kernel tree. Similar implementations exist in other demand paging kernels too.

There have also been many discussions on whether to check the return value of a NULL-returning malloc() at all. See this as an example: http://news.ycombinator.com/item?id=3112309

Mukund

Julien Nabet
2011-10-27 17:47:31 UTC (about 13 years ago)

Patch for cppcheck error "Common realloc mistake"

Le 27/10/2011 18:27, Mukund Sivaraman a