public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/64187] New: Writing to a char array cast from a char * causes a segmentation fault
@ 2014-12-04 19:37 brian.corriveau at ericsson dot com
2014-12-04 19:48 ` [Bug c/64187] " pinskia at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: brian.corriveau at ericsson dot com @ 2014-12-04 19:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64187
Bug ID: 64187
Summary: Writing to a char array cast from a char * causes a
segmentation fault
Product: gcc
Version: 4.3.4
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: brian.corriveau at ericsson dot com
Created attachment 34193
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34193&action=edit
sample that produces segmentation fault
I was trying to work around a coverity optional data[0] overrun issue when I
came across this problem.
The code casts a char * to a char (*)[200], and tries to write to it. This
causes a segmentation fault.
System:
:~/src[1050]uname -a
Linux eussjlxxen204 2.6.32.45-0.3-xen #1 SMP 2011-08-22 10:12:58 +0200 x86_64
x86_64 x86_64 GNU/Linux
Here is the compiler output:
gcc -v -save-temps -g array.c
Using built-in specs.
Target: x86_64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info
--mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64
--enable-languages=c,c++,objc,fortran,obj-c++,java,ada
--enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.3
--enable-ssp --disable-libssp --with-bugurl=http://bugs.opensuse.org/
--with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap
--with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit
--enable-libstdcxx-allocator=new --disable-libstdcxx-pch
--enable-version-specific-runtime-libs --program-suffix=-4.3
--enable-linux-futex --without-system-libunwind --with-cpu=generic
--build=x86_64-suse-linux
Thread model: posix
gcc version 4.3.4 [gcc-4_3-branch revision 152973] (SUSE Linux)
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-g' '-mtune=generic'
/usr/lib64/gcc/x86_64-suse-linux/4.3/cc1 -E -quiet -v array.c -mtune=generic
-fworking-directory -fpch-preprocess -o array.i
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib64/gcc/x86_64-suse-linux/4.3/include
/usr/lib64/gcc/x86_64-suse-linux/4.3/include-fixed
/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/include
/usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-g' '-mtune=generic'
/usr/lib64/gcc/x86_64-suse-linux/4.3/cc1 -fpreprocessed array.i -quiet
-dumpbase array.c -mtune=generic -auxbase array -g -version -o array.s
GNU C (SUSE Linux) version 4.3.4 [gcc-4_3-branch revision 152973]
(x86_64-suse-linux)
compiled by GNU C version 4.3.4 [gcc-4_3-branch revision 152973], GMP
version 4.2.3, MPFR version 2.3.2.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 91a878d77972b76d647d592fefc786fc
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-g' '-mtune=generic'
/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/bin/as -V
-Qy -o array.o array.s
GNU assembler version 2.20.0 (x86_64-suse-linux) using BFD version (GNU
Binutils; SUSE Linux Enterprise 11) 2.20.0.20100122-0.7.9
COMPILER_PATH=/usr/lib64/gcc/x86_64-suse-linux/4.3/:/usr/lib64/gcc/x86_64-suse-linux/4.3/:/usr/lib64/gcc/x86_64-suse-linux/:/usr/lib64/gcc/x86_64-suse-linux/4.3/:/usr/lib64/gcc/x86_64-suse-linux/:/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/bin/
LIBRARY_PATH=/usr/lib64/gcc/x86_64-suse-linux/4.3/:/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/lib/:/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-g' '-mtune=generic'
/usr/lib64/gcc/x86_64-suse-linux/4.3/collect2 --build-id --eh-frame-hdr -m
elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2
/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../lib64/crt1.o
/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../lib64/crti.o
/usr/lib64/gcc/x86_64-suse-linux/4.3/crtbegin.o
-L/usr/lib64/gcc/x86_64-suse-linux/4.3
-L/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../lib64 -L/lib/../lib64
-L/usr/lib/../lib64
-L/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/lib
-L/usr/lib64/gcc/x86_64-suse-linux/4.3/../../.. array.o -lgcc --as-needed
-lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed
/usr/lib64/gcc/x86_64-suse-linux/4.3/crtend.o
/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../lib64/crtn.o
Run output:
:~/src[1047]./a.out
hEllo
Segmentation fault
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/64187] Writing to a char array cast from a char * causes a segmentation fault
2014-12-04 19:37 [Bug c/64187] New: Writing to a char array cast from a char * causes a segmentation fault brian.corriveau at ericsson dot com
@ 2014-12-04 19:48 ` pinskia at gcc dot gnu.org
2014-12-04 21:49 ` brian.corriveau at ericsson dot com
2014-12-04 22:03 ` brian.corriveau at ericsson dot com
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-12-04 19:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64187
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
char *test = "this is a test";
This is a string literal so it stored in constant memory and which is why you
are getting a segfault.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/64187] Writing to a char array cast from a char * causes a segmentation fault
2014-12-04 19:37 [Bug c/64187] New: Writing to a char array cast from a char * causes a segmentation fault brian.corriveau at ericsson dot com
2014-12-04 19:48 ` [Bug c/64187] " pinskia at gcc dot gnu.org
@ 2014-12-04 21:49 ` brian.corriveau at ericsson dot com
2014-12-04 22:03 ` brian.corriveau at ericsson dot com
2 siblings, 0 replies; 4+ messages in thread
From: brian.corriveau at ericsson dot com @ 2014-12-04 21:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64187
--- Comment #2 from Brian <brian.corriveau at ericsson dot com> ---
(In reply to Andrew Pinski from comment #1)
> char *test = "this is a test";
>
>
> This is a string literal so it stored in constant memory and which is why
> you are getting a segfault.
I was thinking "test" would be on the stack, but obviously not.
I did compile with the -Wall option before filing the bug, but I didn't get any
complaints. Maybe this is something that could be improved.
thanks for the speedy answer,
brian
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/64187] Writing to a char array cast from a char * causes a segmentation fault
2014-12-04 19:37 [Bug c/64187] New: Writing to a char array cast from a char * causes a segmentation fault brian.corriveau at ericsson dot com
2014-12-04 19:48 ` [Bug c/64187] " pinskia at gcc dot gnu.org
2014-12-04 21:49 ` brian.corriveau at ericsson dot com
@ 2014-12-04 22:03 ` brian.corriveau at ericsson dot com
2 siblings, 0 replies; 4+ messages in thread
From: brian.corriveau at ericsson dot com @ 2014-12-04 22:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64187
--- Comment #3 from Brian <brian.corriveau at ericsson dot com> ---
Thanks for the speedy reply. I just added a comment on the bug. Maybe
-Wall should catch this kind of thing?
thanks again
brian
pinskia at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64187
>
> Andrew Pinski <pinskia at gcc dot gnu.org> changed:
>
> What |Removed |Added
> ----------------------------------------------------------------------------
> Status|UNCONFIRMED |RESOLVED
> Resolution|--- |INVALID
>
> --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
> char *test = "this is a test";
>
>
> This is a string literal so it stored in constant memory and which is why you
> are getting a segfault.
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-12-04 22:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-04 19:37 [Bug c/64187] New: Writing to a char array cast from a char * causes a segmentation fault brian.corriveau at ericsson dot com
2014-12-04 19:48 ` [Bug c/64187] " pinskia at gcc dot gnu.org
2014-12-04 21:49 ` brian.corriveau at ericsson dot com
2014-12-04 22:03 ` brian.corriveau at ericsson dot com
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).