Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Printf builtin missing v flag support



On Mac OS X (where open_memstream() does not exist), B03print.ztst fails
as follows.

*** 1,2 ****
  once more
! into-the-breach-
--- 1,2 ----
  once more
! 
Test ./B03print.ztst failed: output differs from expected as shown above for:
 unset foo
 print -v foo once more
 print -r -- $foo
 printf -v foo "%s-" into the breach
 print -r -- $foo
Error output:
(eval):printf:4: i/o error: inappropriate ioctl for device
Was testing: print and printf into a variable


A patch is attached below.
fread() returns the number of elements (items) successfully read.
rcount++ for the trailing NULL.


diff --git a/Src/builtin.c b/Src/builtin.c
index 04d8f11..03fefa6 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -4879,10 +4879,10 @@ bin_print(char *name, char **args, Options ops, int func)
 #else
 	rewind(fout);
 	buf = (char *)zalloc(count + 1);
-	rcount = fread(buf, count, 1, fout);
+	rcount = fread(buf, 1, count, fout);
 	if (rcount < count)
 	    zwarnnam(name, "i/o error: %e", errno);
-	buf[rcount] = '\0';
+	buf[rcount++] = '\0';
 #endif
 	queue_signals();
 	stringval = metafy(buf, rcount - 1, META_REALLOC);




Messages sorted by: Reverse Date, Date, Thread, Author