zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Printf builtin missing v flag support
Date: Sat, 2 Jan 2016 13:54:38 -0800	[thread overview]
Message-ID: <160102135438.ZM12227@torch.brasslantern.com> (raw)
In-Reply-To: <160102134237.ZM17072@torch.brasslantern.com>

On Jan 2,  1:42pm, Bart Schaefer wrote:
}
} Having written that out, it looks like there might be bugs with using
} all off -u/-p plus -z/-s/-v plus -c/-C.  Haven't actually tried.  There
} might also be bugs with printf-ing of NUL bytes into the memstream.

Yes, that byte count I keep saying is important was even more important
than I thought.  Also add some error checking on the tempfile branch.


diff --git a/Src/builtin.c b/Src/builtin.c
index 557487c..04d8f11 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -4872,17 +4872,20 @@ bin_print(char *name, char **args, Options ops, int func)
 
     if (OPT_ISSET(ops,'z') || OPT_ISSET(ops,'s') || OPT_ISSET(ops,'v')) {
 #ifdef HAVE_OPEN_MEMSTREAM
-	putc(0, fout);
+	putc(0, fout);		/* not needed?  open_memstream() maintains? */
 	fclose(fout);
 	fout = NULL;
+	rcount = mcount;	/* now includes the trailing NUL we added */
 #else
 	rewind(fout);
 	buf = (char *)zalloc(count + 1);
-	fread(buf, count, 1, fout);
-	buf[count] = '\0';
+	rcount = fread(buf, count, 1, fout);
+	if (rcount < count)
+	    zwarnnam(name, "i/o error: %e", errno);
+	buf[rcount] = '\0';
 #endif
 	queue_signals();
-	stringval = metafy(buf, -1, META_REALLOC);
+	stringval = metafy(buf, rcount - 1, META_REALLOC);
 	if (OPT_ISSET(ops,'z')) {
 	    zpushnode(bufstack, stringval);
 	} else if (OPT_ISSET(ops,'v')) {


  reply	other threads:[~2016-01-02 21:54 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <etPan.5684d3d1.74f2df6b.31ec@Ganymede>
2015-12-31  7:16 ` Starms, William Albert (MU-Student)
2015-12-31 10:44   ` Peter Stephenson
2015-12-31 18:48     ` Bart Schaefer
2016-01-01 21:26       ` Sebastian Gniazdowski
2016-01-01 21:35         ` Sebastian Gniazdowski
2016-01-01 21:52         ` Bart Schaefer
2016-01-01 22:12           ` Sebastian Gniazdowski
2016-01-02  4:17             ` Bart Schaefer
2016-01-02  7:17               ` Sebastian Gniazdowski
2016-01-02 21:42                 ` Bart Schaefer
2016-01-02 21:54                   ` Bart Schaefer [this message]
2016-01-04  5:50                     ` Jun T.
2016-01-04 19:22                       ` Bart Schaefer
2016-01-01 21:57       ` Eric Cook
2016-01-01 22:14         ` Eric Cook
2015-12-31 13:55   ` Eric Cook
2015-12-31 14:05     ` Eric Cook
2016-01-01 18:45   ` Stephane Chazelas
2016-01-01 21:17     ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=160102135438.ZM12227@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).