]> git.netwichtig.de Git - user/henk/code/exim.git/blobdiff - src/src/string.c
Better handling of printing NULL pointers
[user/henk/code/exim.git] / src / src / string.c
index 2de595afb664d3602bc40fc3c50ff728ca7118ab..f3bf343150b499b4135587808f14774ae7540ba0 100644 (file)
@@ -1363,10 +1363,20 @@ while (*fp != 0)
     break;
 
     case 'p':
-    if (p >= last - 24) { yield = FALSE; goto END_FORMAT; }
-    strncpy(newformat, item_start, fp - item_start);
-    newformat[fp - item_start] = 0;
-    p += sprintf(CS p, newformat, va_arg(ap, void *));
+      {
+      void * ptr;
+      if (p >= last - 24) { yield = FALSE; goto END_FORMAT; }
+      /* sprintf() saying "(nil)" for a null pointer seems unreliable.
+      Handle it explicitly. */
+      if ((ptr = va_arg(ap, void *)))
+       {
+       strncpy(newformat, item_start, fp - item_start);
+       newformat[fp - item_start] = 0;
+       p += sprintf(CS p, newformat, ptr);
+       }
+      else
+       p += sprintf(CS p, "(nil)");
+      }
     break;
 
     /* %f format is inherently insecure if the numbers that it may be