From 1554b9e99c26d300f9a23b135689f5e3cc06771a Mon Sep 17 00:00:00 2001 From: rfm Date: Fri, 5 Jul 2013 20:47:41 +0000 Subject: [PATCH] fix potential null pointer deref git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@36840 72102866-910b-0410-8b05-ffd578937521 --- Source/NSDebug.m | 60 ++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/Source/NSDebug.m b/Source/NSDebug.m index 0f4b06802..242eebf7b 100644 --- a/Source/NSDebug.m +++ b/Source/NSDebug.m @@ -525,27 +525,30 @@ _GSDebugAllocationList(BOOL difference) buf = NSZoneMalloc(NSDefaultMallocZone(), siz); } - if (buf) + if (0 == buf) { - pos = 0; - for (i = 0; i < num_classes; i++) + return ""; + } + + pos = 0; + for (i = 0; i < num_classes; i++) + { + int val = the_table[i].count; + + if (difference) { - int val = the_table[i].count; + val -= the_table[i].lastc; + } + the_table[i].lastc = the_table[i].count; - if (difference) - { - val -= the_table[i].lastc; - } - the_table[i].lastc = the_table[i].count; - - if (val != 0) - { - snprintf(&buf[pos], siz - pos, "%d\t%s\n", - val, class_getName(the_table[i].class)); - pos += strlen(&buf[pos]); - } + if (val != 0) + { + snprintf(&buf[pos], siz - pos, "%d\t%s\n", + val, class_getName(the_table[i].class)); + pos += strlen(&buf[pos]); } } + return buf; } @@ -612,21 +615,24 @@ _GSDebugAllocationListAll(void) buf = NSZoneMalloc(NSDefaultMallocZone(), siz); } - if (buf) + if (0 == buf) { - pos = 0; - for (i = 0; i < num_classes; i++) - { - int val = the_table[i].total; + return ""; + } - if (val != 0) - { - snprintf(&buf[pos], siz - pos, "%d\t%s\n", - val, class_getName(the_table[i].class)); - pos += strlen(&buf[pos]); - } + pos = 0; + for (i = 0; i < num_classes; i++) + { + int val = the_table[i].total; + + if (val != 0) + { + snprintf(&buf[pos], siz - pos, "%d\t%s\n", + val, class_getName(the_table[i].class)); + pos += strlen(&buf[pos]); } } + return buf; }