bug-patch
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-patch] "safe.c", line 264: error: zero or negative subscript


From: address@hidden
Subject: [bug-patch] "safe.c", line 264: error: zero or negative subscript
Date: Fri, 2 Oct 2015 20:46:55 -0400 (EDT)

There appears to be a trivial bug in src/safe.c wherein a zero size
array was defined and this is not in compliance with  ISO C99 update
WG14/N1256.  In section 6.7.8 Initialization of the standard there does
not appear to be allowance for a zero size array such as buffer[0]
however we do see this in the GNU world thus : 

section : 6.17 Arrays of Length Zero
https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html

Therefore GCC compiler would most likely just silently accept this
unless I enforced compliance mode. 

Regardless, I am using Oracle Solaris Studio 12.4 on Solaris 10 with the
CFLAGS option -Xc which is very strict : 

    -Xc   (c = conformance) Issues errors and warnings for programs
           that use non-ISO C constructs. This option is strictly 
           conformant ISO C without K&R C compatibility extensions.
           The predefined macro __STDC__ has a value of 1 with 
           the –Xc option.


That explains why I see this during the compile : 

.
.
.
Making all in src
gmake[2]: Entering directory
`/usr/local/build/patch-2.7.5_SunOS5.10_sparcv9.001/src'
  CC       inp.o
  CC       patch.o
  CC       pch.o
  CC       safe.o
"safe.c", line 264: error: zero or negative subscript
cc: acomp failed for safe.c
gmake[2]: *** [safe.o] Error 2
gmake[2]: Leaving directory
`/usr/local/build/patch-2.7.5_SunOS5.10_sparcv9.001/src'
gmake[1]: *** [all-recursive] Error 1
gmake[1]: Leaving directory
`/usr/local/build/patch-2.7.5_SunOS5.10_sparcv9.001'
gmake: *** [all] Error 2
$ 

A somewhat hackary fix is just to make buffer[] a size 1 array like so :


$ diff -c ./src/safe.c_ ./src/safe.c
*** ./src/safe.c_       Sat Mar  7 00:34:20 2015
--- ./src/safe.c        Fri Oct  2 23:34:46 2015
***************
*** 261,267 ****
  struct symlink {
    struct symlink *prev;
    const char *path;
!   char buffer[0];
  };
  
  static void push_symlink (struct symlink **stack, struct symlink
*symlink)
--- 261,267 ----
  struct symlink {
    struct symlink *prev;
    const char *path;
!   char buffer[1]; /* can not have a zero sub-script */
  };
  
  static void push_symlink (struct symlink **stack, struct symlink
*symlink)



That results in the sources compiling just fine and ALL tests pass fine
too : 

============================================================================
Testsuite summary for GNU patch 2.7.5
============================================================================
# TOTAL: 39
# PASS:  33
# SKIP:  5
# XFAIL: 1
# FAIL:  0
# XPASS: 0
# ERROR: 0
============================================================================

cool.

However that buffer[1] probably does not need to exist at all. 

So, feels like a bug.

Dennis Clarke
old unix guy.

ref : Oracle® Solaris Studio 12.4: C User's Guide
      https://docs.oracle.com/cd/E37069_01/html/E37074/bjapp.html


      The ISO C standard section 6.7.8 
      http://c0x.coding-guidelines.com/6.7.8.html


      GNU C Extensions not in the ISO standard.
      https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html#C-Extensions
      https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]