]> Savannah Git Hosting - gnulib.git/commitdiff
quotearg: pacify compiler re unsigned
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 19 Oct 2017 20:03:40 +0000 (13:03 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 19 Oct 2017 20:04:21 +0000 (13:04 -0700)
* lib/quotearg.c (quotearg_n_options):
Rewrite to avoid diagnostic from overly-picky compiler.
Problem reported by Sami Kerola in:
https://lists.gnu.org/archive/html/bug-gnulib/2017-10/msg00060.html

ChangeLog
lib/quotearg.c

index e662c02a57a1900cfe9cd659579b100f4b98d3c2..ed34aa80f3ff455725883e5bceaa43275298978b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2017-10-19  Paul Eggert  <eggert@cs.ucla.edu>
 
+       quotearg: pacify compiler re unsigned
+       * lib/quotearg.c (quotearg_n_options):
+       Rewrite to avoid diagnostic from overly-picky compiler.
+       Problem reported by Sami Kerola in:
+       https://lists.gnu.org/archive/html/bug-gnulib/2017-10/msg00060.html
+
        glob: fix heap buffer overflow
        * lib/glob.c (glob): Fix off-by-one error introduced into
        glibc in commit dd7d45e838a42b0ed470c44b55901ea98d0c2bab
index df602698e39b2a96e00cac4617878368f2b6174a..8e432e1343c1a6893408bb403a4b7c901357b048 100644 (file)
@@ -887,8 +887,9 @@ quotearg_n_options (int n, char const *arg, size_t argsize,
   if (nslots <= n)
     {
       bool preallocated = (sv == &slotvec0);
+      int nmax = MIN (INT_MAX, MIN (PTRDIFF_MAX, SIZE_MAX) / sizeof *sv) - 1;
 
-      if (MIN (INT_MAX, MIN (PTRDIFF_MAX, SIZE_MAX) / sizeof *sv) <= n)
+      if (nmax < n)
         xalloc_die ();
 
       slotvec = sv = xrealloc (preallocated ? NULL : sv, (n + 1) * sizeof *sv);