This is the mail archive of the glibc-bugs@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/130] New: strpbrk() macro expansion has uncertain type (char * or NULL)


>  $ cat foo.c
>  #include <string.h>
>  int main(int argc, char *argv[]) {
>          return (int) ((strpbrk("string", "n")) - "string");
>  }
>  $ /usr/i686-pc-linux-gnu/gcc-bin/3.4/gcc -O foo.c
>  foo.c: In function `main':
>  foo.c:3: error: invalid operands to binary -

-O is necessary to make gcc include the optimising macro definition of strpbrk()
in bits/string2.h:

#  define strpbrk(s, accept) \
  __extension__								      \
  ({ char __a0, __a1, __a2;						      \
     (__builtin_constant_p (accept) && __string2_1bptr_p (accept)	      \
      ? ((__a0 = ((__const char  *) (accept))[0], __a0 == '\0')		      \
	 ? ((void) (s), NULL)						      \
	 : ((__a1 = ((__const char *) (accept))[1], __a1 == '\0')	      \
	    ? strchr (s, __a0)						      \
	    : ((__a2 = ((__const char *) (accept))[2], __a2 == '\0')	      \
	       ? __strpbrk_c2 (s, __a0, __a1)				      \
	       : (((__const char *) (accept))[3] == '\0'		      \
		  ? __strpbrk_c3 (s, __a0, __a1, __a2)			      \
		  : strpbrk (s, accept)))))				      \
      : strpbrk (s, accept)); })
# endif

Offending line is:
	 ? ((void) (s), NULL)						      \

This is not detected as a bug when compiling with gcc 3.3.

Test case and patch attached.

-- 
           Summary: strpbrk() macro expansion has uncertain type (char * or
                    NULL)
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: gotom at debian dot or dot jp
        ReportedBy: ed at catmur dot co dot uk
                CC: glibc-bugs at sources dot redhat dot com
  GCC host triplet: i686-pc-linux-gnu


http://sources.redhat.com/bugzilla/show_bug.cgi?id=130

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]