]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Enhance my 'sresize' macro so that it type-checks the pointer you pass
authorSimon Tatham <anakin@pobox.com>
Fri, 18 May 2012 19:51:11 +0000 (19:51 +0000)
committerSimon Tatham <anakin@pobox.com>
Fri, 18 May 2012 19:51:11 +0000 (19:51 +0000)
_in_ to it, as well as the one it returns. Why have I never thought of
doing that before?!

[originally from svn r9539]

puttymem.h

index 06c294d91682df8436b94cc017f074323883d561..6ef3f794931a326feb358a3fb1f80ff4c8401e97 100644 (file)
@@ -37,6 +37,7 @@ void safefree(void *);
  */
 #define snew(type) ((type *)snmalloc(1, sizeof(type)))
 #define snewn(n, type) ((type *)snmalloc((n), sizeof(type)))
-#define sresize(ptr, n, type) ((type *)snrealloc((ptr), (n), sizeof(type)))
+#define sresize(ptr, n, type) \
+    ((type *)snrealloc((sizeof((type *)0 == (ptr)), (ptr)), (n), sizeof(type)))
 
 #endif