Bug 33530 - void * arithmetic in bits/string2.h
void * arithmetic in bits/string2.h
Product: Red Hat Linux
Classification: Retired
Component: glibc (Show other bugs)
i586 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Aaron Brown
Depends On:
  Show dependency treegraph
Reported: 2001-03-27 20:03 EST by Peter Ajamian
Modified: 2007-04-18 12:32 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2001-03-28 01:41:27 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Peter Ajamian 2001-03-27 20:03:53 EST
From Bugzilla Helper:
User-Agent: Mozilla/4.73 [en] (Win95; U)

I noticed this when building rpm with a patch that I added in (the one to fix the recursive %if problem in case it matters).
I got a bunch of warnings like this...
/usr/include/bits/string2.h:237: warning: pointer of type `void *' used in arithmetic

Checking the actual line in string2.h...
      __u = __extension__ ((void *) __u + 1);

There's a bunch of those in string2.h

It's explicitly cast to a void * then has pointer arithmetic done on it that way?  Can someone explain why this is?  I'm not the most advanced C 
programmer, but I'm pretty sure that you're _not_ supposed to do pointer arithmetic on a void *.

Reproducible: Always
Steps to Reproduce:
Compile something with -Wall and #include <string.h>.
I specifically saw the problem trying to compile the rpm package and have not tried anything else.	

Actual Results:  Got the warnings mentioned above.

Expected Results:  No warnings.

see above.
Comment 1 Peter Ajamian 2001-03-27 22:04:13 EST
I just noticed that rpm is compiling with the -Wpointer-arith flag, I suspect that that is also needed to generate the warning.

Additional info:  $rpm -q glibc

The version of rpm I am attempting to compile is rpm-4.0.2-7x which has been tweaked to add in the above mentioned patch.

When I get time later on I'll try to come up with a simple test case that will reproduce the problem.
Comment 2 Peter Ajamian 2001-03-28 01:03:55 EST
Okay, I managed to reproduce this in very simple means (note it also requires optimization to be turned on)...

cat << EOF > test.c
#include <string.h>
int main(void) {return 0;}
gcc -O -Wpointer-arith -o /dev/null test.c

Output of this is as follows...

/usr/include/bits/string2.h: In function `__strcpy_small':
In file included from /usr/include/string.h:361,
                 from test.c:1:
/usr/include/bits/string2.h:418: warning: pointer of type `void *' used in arithmetic
/usr/include/bits/string2.h:426: warning: pointer of type `void *' used in arithmetic
/usr/include/bits/string2.h:431: warning: pointer of type `void *' used in arithmetic
/usr/include/bits/string2.h:436: warning: pointer of type `void *' used in arithmetic
/usr/include/bits/string2.h:438: warning: pointer of type `void *' used in arithmetic
/usr/include/bits/string2.h:443: warning: pointer of type `void *' used in arithmetic

Just to verify that the file string2.h _really_ came from where I think it does...

$rpm -qf /usr/include/bits/string2.h
$rpm -V glibc-devel-2.2-12
Comment 3 Peter Ajamian 2001-03-28 01:41:23 EST
Sorry to keep tacking more onto this, anyways...

I found this GNU bug report for libc which describes the problem:

I reported this one as ver 7.0 because I had updated glibc to version 2.2, but I'm still running gcc from RedHat 6.0 (which is actually
egcs).  Apparently updating to a version of gcc >= 2.96 _should_ fix the problem (though I'm not gonna bother testing it since I now
know that it's not a warning which need be taken seriously).  I'll leave this for someone else to close out because it may warrant an
errata for 6.x.
Comment 4 Jakub Jelinek 2001-03-28 03:25:41 EST
The question is which compiler do you use.
This is a compiler bug and it is for sure fixed in both gcc-2.96-RH and
compat-egcs we shipped in 7.0. 2.95.2 does not have this fixed and from quick
look at the 2.95.2 -> 2.95.3 diff 2.95.3 probably does not have it fixed either.
gcc supports void * arithmetics as an extension, and this is clearly
marked with __extension__.

Note You need to log in before you can comment on or make changes to this bug.