Mosè Giordano wrote:
> Without the patch I get a
> 
>     shift: can't shift that many
> 
> error.

Thanks. It's preferable to get an error, since callers should not pass --prefix
without an argument operand. However, the shell script should not be relying on
undefined behavior to report the error. I installed the attached patch, which
should fix that.
From dd65129dbb0c5c40ee64d189bcee5dd0765edc7a Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Sun, 8 May 2016 11:38:22 -0700
Subject: [PATCH] git-version-gen: avoid undefined shift
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Problem reported by Mosè Giordano in:
http://lists.gnu.org/archive/html/bug-gnulib/2016-05/msg00012.html
* build-aux/git-version-gen: Avoid undefined behavior if invoked
with --prefix or --fallback but without a later argument.  While
we're at it, omit unnecessary quotes.
---
 ChangeLog                 | 9 +++++++++
 build-aux/git-version-gen | 6 +++---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 803a008..fe747e5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2016-05-08  Paul Eggert  <[email protected]>
+
+	git-version-gen: avoid undefined shift
+	Problem reported by Mosè Giordano in:
+	http://lists.gnu.org/archive/html/bug-gnulib/2016-05/msg00012.html
+	* build-aux/git-version-gen: Avoid undefined behavior if invoked
+	with --prefix or --fallback but without a later argument.  While
+	we're at it, omit unnecessary quotes.
+
 2016-05-04  Paul Eggert  <[email protected]>
 
 	glob: merge glibc changes into lib/glob.c
diff --git a/build-aux/git-version-gen b/build-aux/git-version-gen
index 6c56147..bd2c4b6 100755
--- a/build-aux/git-version-gen
+++ b/build-aux/git-version-gen
@@ -1,6 +1,6 @@
 #!/bin/sh
 # Print a version string.
-scriptversion=2016-01-11.22; # UTC
+scriptversion=2016-05-08.18; # UTC
 
 # Copyright (C) 2007-2016 Free Software Foundation, Inc.
 #
@@ -101,8 +101,8 @@ while test $# -gt 0; do
   case $1 in
     --help) echo "$usage"; exit 0;;
     --version) echo "$version"; exit 0;;
-    --prefix) shift; prefix="$1";;
-    --fallback) shift; fallback="$1";;
+    --prefix) shift; prefix=${1?};;
+    --fallback) shift; fallback=${1?};;
     -*)
       echo "$0: Unknown option '$1'." >&2
       echo "$0: Try '--help' for more information." >&2
-- 
2.7.4

Reply via email to