public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/35948]  New: -D_FORTIFY_SOURCE discards qualifier overrides on {str,mem}cpy
@ 2008-04-15 16:29 kees at outflux dot net
  2008-04-15 16:36 ` [Bug c/35948] " pinskia at gcc dot gnu dot org
  2008-04-15 16:44 ` kees at outflux dot net
  0 siblings, 2 replies; 3+ messages in thread
From: kees at outflux dot net @ 2008-04-15 16:29 UTC (permalink / raw)
  To: gcc-bugs

The following source, without the "(void*)" overrides, will throw an warning
(as expected), when compiled with -Wall:

 $ gcc -o memcpy-fortify -Wall memcpy-fortify.c
 memcpy-fortify.c: In function 'main':
 memcpy-fortify.c:21: warning: passing argument 1 of 'memcpy' discards
qualifiers from pointer target type
 memcpy-fortify.c:22: warning: passing argument 1 of 'strcpy' discards
qualifiers from pointer target type

With "(void*)" it is (as expected) silent. With -O2, it is silent, but with
-D_FORTIFY_SOURCE != 0, the qualifier override is ignored:

 $ gcc -o memcpy-fortify -Wall -O2 -D_FORTIFY_SOURCE=2 memcpy-fortify.c
 memcpy-fortify.c: In function 'main':
 memcpy-fortify.c:21: warning: passing argument 1 of 'memcpy' discards
qualifiers from pointer target type
 memcpy-fortify.c:22: warning: passing argument 1 of 'strcpy' discards
qualifiers from pointer target type

This will cause problems for builds that run with -Werror.

/*
 * gcc -o memcpy-fortify -Wall -Werror -O2 -D_FORTIFY_SOURCE=2 memcpy-fortify.c
 *
 */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <string.h>
#include <stdint.h>
#include <inttypes.h>

int main(int argc, char * argv[])
{
    char *foo = strdup("string one");
    char *bar = strdup("string two");
    const char *baz = (const char *)foo;

    printf("%s\n", foo);

    memcpy((void*)baz, bar, strlen(bar)+1);
    strcpy((void*)baz, bar);

    printf("%s\n", foo);

    return 0;
}


-- 
           Summary: -D_FORTIFY_SOURCE discards qualifier overrides on
                    {str,mem}cpy
           Product: gcc
           Version: 4.2.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kees at outflux dot net


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35948


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/35948] -D_FORTIFY_SOURCE discards qualifier overrides on {str,mem}cpy
  2008-04-15 16:29 [Bug c/35948] New: -D_FORTIFY_SOURCE discards qualifier overrides on {str,mem}cpy kees at outflux dot net
@ 2008-04-15 16:36 ` pinskia at gcc dot gnu dot org
  2008-04-15 16:44 ` kees at outflux dot net
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-04-15 16:36 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2008-04-15 16:35 -------
This is not a GCC bug but rather a glibc issue.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35948


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/35948] -D_FORTIFY_SOURCE discards qualifier overrides on {str,mem}cpy
  2008-04-15 16:29 [Bug c/35948] New: -D_FORTIFY_SOURCE discards qualifier overrides on {str,mem}cpy kees at outflux dot net
  2008-04-15 16:36 ` [Bug c/35948] " pinskia at gcc dot gnu dot org
@ 2008-04-15 16:44 ` kees at outflux dot net
  1 sibling, 0 replies; 3+ messages in thread
From: kees at outflux dot net @ 2008-04-15 16:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from kees at outflux dot net  2008-04-15 16:44 -------
Erk, right.  Sorry for the noise.


-- 

kees at outflux dot net changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35948


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-04-15 16:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-15 16:29 [Bug c/35948] New: -D_FORTIFY_SOURCE discards qualifier overrides on {str,mem}cpy kees at outflux dot net
2008-04-15 16:36 ` [Bug c/35948] " pinskia at gcc dot gnu dot org
2008-04-15 16:44 ` kees at outflux dot net

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).