zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: zsh-workers@zsh.org
Subject: PATCH: Fix two bugs in typeset_setbase
Date: Sun,  3 May 2015 22:36:02 +0200	[thread overview]
Message-ID: <1430685362-12270-1-git-send-email-mikachu@gmail.com> (raw)
In-Reply-To: <CAOcd6hrtTa7WVerarsU9+ZTWxa5G0g8f9Z+PGKCfMWZ7JWT-UA@mail.gmail.com>

We refused to set the base outside [2,36], but this restriction should
only apply to integers (where the base is actually the base). For float
values, the precision can be anything. We also failed to actually enforce
this limitation in either of these cases, but only printed the error
message. We now only update the base if it was valid.

---
 Src/builtin.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/Src/builtin.c b/Src/builtin.c
index 0113757..1243263 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -1865,7 +1865,7 @@ typeset_setbase(const char *name, Param pm, Options ops, int on, int always)
 
     if (arg) {
 	char *eptr;
-	pm->base = (int)zstrtol(arg, &eptr, 10);
+	int base = (int)zstrtol(arg, &eptr, 10);
 	if (*eptr) {
 	    if (on & PM_INTEGER)
 		zwarnnam(name, "bad base value: %s", arg);
@@ -1873,11 +1873,12 @@ typeset_setbase(const char *name, Param pm, Options ops, int on, int always)
 		zwarnnam(name, "bad precision value: %s", arg);
 	    return 1;
 	}
-	if (pm->base < 2 || pm->base > 36) {
+	if ((on & PM_INTEGER) && (base < 2 || base > 36)) {
 	    zwarnnam(name, "invalid base (must be 2 to 36 inclusive): %d",
-		     pm->base);
+		     base);
 	    return 1;
 	}
+	pm->base = base;
     } else if (always)
 	pm->base = 0;
 
-- 
2.4.0


  reply	other threads:[~2015-05-03 20:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-03 19:21 'typeset -F' behaves unexpectedly for "-F 1" and "-F 0" David Hughes
2015-05-03 20:36 ` Mikael Magnusson [this message]
2015-05-03 20:43   ` PATCH: Fix two bugs in typeset_setbase Mikael Magnusson
2015-05-03 21:24     ` Peter Stephenson
2015-05-03 22:40       ` Mikael Magnusson
2015-05-04  2:34         ` Mikael Magnusson

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=1430685362-12270-1-git-send-email-mikachu@gmail.com \
    --to=mikachu@gmail.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).