[PATCH] zerrmsg: handle null pointers with %s/%l

dana <[email protected]> Sat, 13 Jun 2026 03:33:03 +0000
Newsgroups gmane.comp.shells.zsh.devel
Message-ID <[email protected]>
same behaviour as printf(3)

a null pointer in an end-user error message is probably a logic error. but this
is useful for lazy debugging

dana


diff --git a/Src/utils.c b/Src/utils.c
index 0b4bb9a82..4de23b6a2 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -313,12 +313,12 @@ zerrmsg(FILE *file, const char *fmt, va_list ap)
 	    switch (*fmt++) {
 	    case 's':
 		str = va_arg(ap, const char *);
-		nicezputs(str, file);
+		nicezputs(str ? str : "(null)", file);
 		break;
 	    case 'l': {
 		str = va_arg(ap, const char *);
 		num = va_arg(ap, int);
-		fwrite(str, num, 1, file);
+		fwrite(str ? str : "(null)", num, 1, file);
 		break;
 	    }
 	    case 'L':