public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug debug/20229] New: -Wcast-qual option is easily evaded
@ 2005-02-27 16:01 kmk at ssl dot org
  2005-02-27 16:08 ` [Bug c/20229] " pinskia at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: kmk at ssl dot org @ 2005-02-27 16:01 UTC (permalink / raw)
  To: gcc-bugs

The -Wcast-qual option in GCC can easily be evaded by "clever" hacks, which
seriously reduces the utility of this feature in catching dangerous behavior
intentionally hidden by programmers from unit testers.

Here is code for a test case (which is extremely simple, and includes no
headers, so I am sending the source rather than the virtually-identical
intermediate file, which lacks comments):
-------------------

void evil_string_modifier(char *s) { s[0] = 0; }

int main(void) {

// This warns, as expected:
  evil_string_modifier("Test string one.");

// This also warns, as expected:
  evil_string_modifier((char *)"Test string two.");

// This, however, does not warn...but should:
  evil_string_modifier((char *)(int)"Test string three.");

}

---------------------------
The compiler output for the code given above:

Using built-in specs.
Configured with: ./configure --prefix=/usr --host=i386-just-dragonflybsd
Thread model: posix
gcc version 3.4.3 [DragonFly] (propolice, visibility)
 /usr/libexec/gcc34/cc1 -E -quiet -v -iprefix
/usr/libexec/gcc34/../gcc34//3.4.1/ bug.c -march=pentium3 -W -Wall
-Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wno-uninitialized
-Wall -W -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type
-Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wchar-subscripts
-Winline -Wnested-externs -Wredundant-decls -O -o bug.i
ignoring nonexistent directory "/usr/libexec/gcc34/../gcc34//3.4.1/include"
ignoring nonexistent directory "/usr/libexec/gcc34/../gcc34//3.4.1/libdata/gcc34"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include
 /usr/libdata/gcc34
End of search list.
 /usr/libexec/gcc34/cc1 -fpreprocessed bug.i -quiet -dumpbase bug.c
-march=pentium3 -auxbase bug -O -W -Wall -Wstrict-prototypes
-Wmissing-prototypes -Wpointer-arith -Wno-uninitialized -Wall -W
-Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type
-Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wchar-subscripts
-Winline -Wnested-externs -Wredundant-decls -version -o bug.s
GNU C version 3.4.3 (i386-just-dragonflybsd)
        compiled by GNU C version 2.95.4 20020320 [DragonFly].
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
bug.c:2: warning: no previous prototype for 'evil_string_modifier'
bug.c: In function `main':
bug.c:7: warning: passing arg 1 of `evil_string_modifier' discards qualifiers
from pointer target type
bug.c:10: warning: cast discards qualifiers from pointer target type
bug.c:15: warning: control reaches end of non-void function
 as -o bug.o bug.s
 ld -V -dynamic-linker /usr/libexec/ld-elf.so.1 -o bug /usr/lib/crt1.o
/usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib/gcc34 bug.o -lgcc -lc -lgcc
/usr/lib/crtend.o /usr/lib/crtn.o
GNU ld version 2.15 [DragonFly] 2004-05-17
  Supported emulations:
   elf_i386

-- 
           Summary: -Wcast-qual option is easily evaded
           Product: gcc
           Version: 3.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: debug
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kmk at ssl dot org
                CC: gcc-bugs at gcc dot gnu dot org


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


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

end of thread, other threads:[~2005-02-27 22:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-27 16:01 [Bug debug/20229] New: -Wcast-qual option is easily evaded kmk at ssl dot org
2005-02-27 16:08 ` [Bug c/20229] " pinskia at gcc dot gnu dot org
2005-02-27 16:33 ` kmk at ssl dot org
2005-02-27 19:49 ` schwab at suse dot de
2005-02-27 20:45 ` joseph at codesourcery dot com
2005-02-28  8:28 ` kmk at ssl dot org
2005-02-28  8:39 ` kmk at ssl dot org

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).