summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Harris <jgh146exb@wizmail.org>2017-10-05 21:54:28 +0100
committerJeremy Harris <jgh146exb@wizmail.org>2017-10-05 21:54:28 +0100
commit2e8db779f9d0753bd1f235e1d3d6ae27cecfd7d2 (patch)
treecc859346127142e2219a4ce22e8477611a23c147
parent8255135bf80545a31493a83348a4e8da901a4768 (diff)
Fix debug output for NULL pointers on FreeBSD.
The testsuite had failures, mostly in DB opens finding no existing file, where debug output to stderr showed "0xAAAAAAAA" rather than "(nil)". Code it explicitly, at least in %p handling, rather than relying on sprintf() bevahiour.
-rw-r--r--src/src/string.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/src/string.c b/src/src/string.c
index 2de595afb..3857e1120 100644
--- a/src/src/string.c
+++ b/src/src/string.c
@@ -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 doesn't work
+ on FreeBSD; we get "0xAAAAAAAA". 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, va_arg(ap, void *));
+ }
+ else
+ p += sprintf(CS p, "(nil)");
+ }
break;
/* %f format is inherently insecure if the numbers that it may be