zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <Peter.Stephenson@csr.com>
To: "Zsh Hackers' List" <zsh-workers@zsh.org>
Subject: Re: Test failure with negative substring offsets
Date: Mon, 23 May 2011 16:56:14 +0100	[thread overview]
Message-ID: <20110523165614.5e638a17@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <BANLkTinUaE7S0UF67empL53Vqbs=dqA1tw@mail.gmail.com>

On Mon, 23 May 2011 17:41:50 +0200
İsmail Dönmez <ismail@namtrac.org> wrote:
> It passes for me on 64bit machines and fails on 32bit machines. Hope
> that helps.

ahhhhh... yes, that was exactly the clue I needed, thank you.

stdarg doesn't know the arguments need to be converted to integers to
fit the size being claimed in the printf prototype.

There might be a few more of these around, hidden by the fact that
there's only one integer argument and it's being passed little-endian,
so it would fail e.g. on Solaris 32-bit with large file support.

The second part is paranoia...  the stdarg manual says the va_list ap is
undefined after return from a function, so it's safest to run va_end()
on it within the function where it's been used.

Index: Src/subst.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/subst.c,v
retrieving revision 1.123
diff -p -u -r1.123 subst.c
--- Src/subst.c	19 May 2011 16:24:38 -0000	1.123
+++ Src/subst.c	23 May 2011 15:53:08 -0000
@@ -2892,7 +2892,7 @@ paramsubst(LinkList l, LinkNode n, char 
 			    length += alen - offset;
 			if (length < 0) {
 			    zerr("substring expression: %d < %d",
-			         length + offset, offset);
+			         (int)(length + offset), (int)offset);
 			    return NULL;
 			}
 		    } else
@@ -2942,7 +2942,8 @@ paramsubst(LinkList l, LinkNode n, char 
 			    }
 			    if (length < 0) {
 				zerr("substring expression: %d < %d",
-				     length + given_offset, given_offset);
+				     (int)(length + given_offset),
+				     (int)given_offset);
 				return NULL;
 			    }
 			}
Index: Src/utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/utils.c,v
retrieving revision 1.258
diff -p -u -r1.258 utils.c
--- Src/utils.c	9 May 2011 09:49:09 -0000	1.258
+++ Src/utils.c	23 May 2011 15:53:09 -0000
@@ -155,7 +155,6 @@ VA_DCL
     VA_START(ap, fmt);
     VA_GET_ARG(ap, fmt, const char *);
     zwarning(NULL, fmt, ap);
-    va_end(ap);
     errflag = 1;
 }
 
@@ -175,7 +174,6 @@ VA_DCL
     VA_GET_ARG(ap, cmd, const char *);
     VA_GET_ARG(ap, fmt, const char *);
     zwarning(cmd, fmt, ap);
-    va_end(ap);
     errflag = 1;
 }
 
@@ -193,7 +191,6 @@ VA_DCL
     VA_START(ap, fmt);
     VA_GET_ARG(ap, fmt, const char *);
     zwarning(NULL, fmt, ap);
-    va_end(ap);
 }
 
 /**/
@@ -212,7 +209,6 @@ VA_DCL
     VA_GET_ARG(ap, cmd, const char *);
     VA_GET_ARG(ap, fmt, const char *);
     zwarning(cmd, fmt, ap);
-    va_end(ap);
 }
 
 
@@ -236,7 +232,6 @@ VA_DCL
 	fclose(file);
     } else
 	zerrmsg(stderr, message, ap);
-    va_end(ap);
 }
 
 #endif /* DEBUG */
@@ -341,6 +336,8 @@ zerrmsg(FILE *file, const char *fmt, va_
 	}
     putc('\n', file);
     fflush(file);
+
+    va_end(ap);
 }
 
 /* Output a single character, for the termcap routines.     *

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom


  parent reply	other threads:[~2011-05-23 15:56 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-23 15:10 Peter Stephenson
2011-05-23 15:24 ` Mikael Magnusson
2011-05-23 15:41   ` İsmail Dönmez
2011-05-23 15:52     ` Mikael Magnusson
2011-05-23 15:58       ` Bart Schaefer
2011-05-23 16:00         ` Mikael Magnusson
2011-05-23 15:56     ` Peter Stephenson [this message]
2011-05-23 16:08       ` Peter Stephenson
2011-05-23 16:10       ` Bart Schaefer
2011-05-23 16:16         ` Peter Stephenson
2011-05-23 16:19         ` Mikael Magnusson
2011-05-23 16:27           ` Peter Stephenson
2011-05-23 16:34             ` Mikael Magnusson
2011-05-23 16:40               ` Peter Stephenson
2011-05-23 16:52                 ` Peter Stephenson

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=20110523165614.5e638a17@pwslap01u.europe.root.pri \
    --to=peter.stephenson@csr.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).