Open GoogleCodeExporter opened 9 years ago
I've tried to reproduce this problem but haven't been able to. I've even tried
under "valgrind" on linux but it identified no memory errors.
What platform are you doing this on?
Original comment by zik.sale...@gmail.com
on 19 Feb 2011 at 10:32
Gentoo Linux x86_64
I've typed everything as shown in the example.
Original comment by belli...@asiotec.org
on 19 Feb 2011 at 10:52
starting picoc v2.1 beta r557
picoc> int n = 5;
picoc> int *k;
picoc> **k = &n;
^
:3: NULL pointer dereference
picoc> *k = &n;
^
:3: NULL pointer dereference
picoc> *k = n;
^
:3: NULL pointer dereference
picoc> k = n;
^
:3: invalid operation
picoc> k = &n;
picoc> **k = &n;
Segmentation fault
This shows that segmentation fault does not occur everytime...
PicoC is built with gcc 4.4.3 if this helps:
Using built-in specs.
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-4.4.3/work/gcc-4.4.3/configure
--prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.4.3
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.3/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.4.3
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.4.3/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.4.3/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.3/include/g++-v4
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec
--disable-fixed-point --without-ppl --without-cloog --enable-nls
--without-included-gettext --with-system-zlib --disable-werror
--enable-secureplt --enable-multilib --enable-libmudflap --disable-libssp
--enable-libgomp
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.4.3/python
--enable-checking=release --disable-libgcj --enable-languages=c,c++
--enable-shared --enable-threads=posix --enable-__cxa_atexit
--enable-clocale=gnu --with-bugurl=http://bugs.gentoo.org/
--with-pkgversion='Gentoo 4.4.3 p1.0'
Thread model: posix
gcc version 4.4.3 (Gentoo 4.4.3 p1.0)
Original comment by belli...@asiotec.org
on 19 Feb 2011 at 11:03
Thanks. I'll try it on a linux x86-64 system and see how it goes. It may be
related to some portability changes I made recently.
Original comment by zik.sale...@gmail.com
on 19 Feb 2011 at 11:05
I tried this on a couple of systems and haven't yet managed to make it fail.
Can you try it again with the v2.1 release code?
Original comment by zik.sale...@gmail.com
on 22 Feb 2011 at 11:13
$ make clean
rm -f picoc picoc.o table.o lex.o parse.o expression.o heap.o type.o variable.o
clibrary.o platform.o include.o platform/platform_unix.o
platform/library_unix.o cstdlib/stdio.o cstdlib/math.o cstdlib/string.o
cstdlib/stdlib.o cstdlib/time.o cstdlib/errno.o cstdlib/ctype.o
cstdlib/stdbool.o cstdlib/unistd.o *~
$ svn up
U expression.c
U cstdlib/stdio.c
U platform/library_surveyor.c
U clibrary.c
U interpreter.h
U parse.c
U type.c
U tests/Makefile
A tests/54_goto.c
A tests/54_goto.expect
U lex.c
U Makefile
U picoc.c
Updated to revision 569.
$ make
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\" -c -o picoc.o
picoc.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\" -c -o table.o
table.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\" -c -o lex.o lex.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\" -c -o parse.o
parse.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\" -c -o
expression.o expression.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\" -c -o heap.o
heap.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\" -c -o type.o
type.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\" -c -o variable.o
variable.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\" -c -o clibrary.o
clibrary.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\" -c -o platform.o
platform.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\" -c -o include.o
include.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\" -c -o
platform/platform_unix.o platform/platform_unix.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\" -c -o
platform/library_unix.o platform/library_unix.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\" -c -o
cstdlib/stdio.o cstdlib/stdio.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\" -c -o
cstdlib/math.o cstdlib/math.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\" -c -o
cstdlib/string.o cstdlib/string.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\" -c -o
cstdlib/stdlib.o cstdlib/stdlib.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\" -c -o
cstdlib/time.o cstdlib/time.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\" -c -o
cstdlib/errno.o cstdlib/errno.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\" -c -o
cstdlib/ctype.o cstdlib/ctype.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\" -c -o
cstdlib/stdbool.o cstdlib/stdbool.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\" -c -o
cstdlib/unistd.o cstdlib/unistd.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\" -o picoc picoc.o
table.o lex.o parse.o expression.o heap.o type.o variable.o clibrary.o
platform.o include.o platform/platform_unix.o platform/library_unix.o
cstdlib/stdio.o cstdlib/math.o cstdlib/string.o cstdlib/stdlib.o cstdlib/time.o
cstdlib/errno.o cstdlib/ctype.o cstdlib/stdbool.o cstdlib/unistd.o -lm
-lreadline
$ ./picoc -i
starting picoc v2.1 beta r569
picoc> int n = 5;
picoc> int *k;
picoc> **k = &n;
^
:3: NULL pointer dereference
picoc> *k = n;
^
:3: NULL pointer dereference
picoc> k = n;
^
:3: invalid operation
picoc> k = &n;
picoc> **k = &n;
Segmentation fault
And some information about system:
$ file picoc
picoc: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked
(uses shared libs), for GNU/Linux 2.6.9, not stripped
$ gcc -v
Using built-in specs.
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-4.4.3/work/gcc-4.4.3/configure
--prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.4.3
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.3/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.4.3
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.4.3/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.4.3/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.3/include/g++-v4
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec
--disable-fixed-point --without-ppl --without-cloog --enable-nls
--without-included-gettext --with-system-zlib --disable-werror
--enable-secureplt --enable-multilib --enable-libmudflap --disable-libssp
--enable-libgomp
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.4.3/python
--enable-checking=release --disable-libgcj --enable-languages=c,c++
--enable-shared --enable-threads=posix --enable-__cxa_atexit
--enable-clocale=gnu --with-bugurl=http://bugs.gentoo.org/
--with-pkgversion='Gentoo 4.4.3 p1.0'
Thread model: posix
gcc version 4.4.3 (Gentoo 4.4.3 p1.0)
$ uname -a
Linux NoteBelliash 2.6.35-zen2 #3 ZEN SMP PREEMPT Sat Nov 20 18:23:42 CET 2010
x86_64 Intel(R) Core(TM) i7 CPU Q 720 @ 1.60GHz GenuineIntel GNU/Linu
As you can see, it still occurs to me.
If you want me to do some specific work, please let me know and i will try to
help you investigate that problem.
Original comment by belli...@asiotec.org
on 23 Feb 2011 at 11:18
I tried this on 2nd machine:
BellSrv[~/picoc-read-only]> uname -a
Linux BellSrv 2.6.37-hardened #1 SMP Thu Jan 27 20:03:35 CET 2011 x86_64
Intel(R) Atom(TM) CPU D510 @ 1.66GHz GenuineIntel GNU/Linux
BellSrv[~/picoc-read-only]> gcc -v
Using built-in specs.
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-4.4.5/work/gcc-4.4.5/configure
--prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.4.5
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.5/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.4.5
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.4.5/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.4.5/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.5/include/g++-v4
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec
--disable-fixed-point --without-ppl --without-cloog --enable-nls
--without-included-gettext --with-system-zlib --disable-werror
--enable-secureplt --enable-multilib --enable-libmudflap --disable-libssp
--enable-libgomp
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.4.5/python
--enable-checking=release --disable-libgcj --enable-languages=c,c++
--enable-shared --enable-threads=posix --enable-__cxa_atexit
--enable-clocale=gnu --with-bugurl=http://bugs.gentoo.org/
--with-pkgversion='Gentoo 4.4.5 p1.0, pie-0.4.5'
Thread model: posix
gcc version 4.4.5 (Gentoo 4.4.5 p1.0, pie-0.4.5)
I checked out new clean version directly from SVN, as i haven't got a copy
there, compiled it and tried the same code as above.
The result was segmentation fault also...
Original comment by belli...@asiotec.org
on 23 Feb 2011 at 11:30
Maybe this will help:
$ ./picoc -i
starting picoc v2.1 beta r569M
picoc> int n=5;
picoc> int *k;
picoc> k=&n;
picoc> **k=&n;
Segmentation fault
=============================================================
$ cat test.c
#include <stdio.h>
void main() {
int n =5;
int *k;
k = &n;
**k = &n;
}
$ ./picoc test.c
Segmentation fault
=============================================================
$ strace ./picoc test.c
execve("./picoc", ["./picoc", "test.c"], [/* 69 vars */]) = 0
brk(0) = 0x8ab000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x7f63603aa000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x7f63603a9000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=189062, ...}) = 0
mmap(NULL, 189062, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f636037a000
close(3) = 0
open("/lib/libm.so.6", O_RDONLY) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\200>\0\0\0\0\0\0"...,
832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=530552, ...}) = 0
mmap(NULL, 2625752, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) =
0x7f635ff0b000
mprotect(0x7f635ff8c000, 2093056, PROT_NONE) = 0
mmap(0x7f636018b000, 8192, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x80000) = 0x7f636018b000
close(3) = 0
open("/lib/libreadline.so.6", O_RDONLY) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\240j\1\0\0\0\0\0"...,
832) = 832
fstat(3, {st_mode=S_IFREG|0555, st_size=275640, ...}) = 0
mmap(NULL, 2376456, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) =
0x7f635fcc6000
mprotect(0x7f635fd02000, 2093056, PROT_NONE) = 0
mmap(0x7f635ff01000, 32768, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3b000) = 0x7f635ff01000
mmap(0x7f635ff09000, 4872, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f635ff09000
close(3) = 0
open("/lib/libc.so.6", O_RDONLY) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\353\1\0\0\0\0\0"...,
832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1387696, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x7f6360379000
mmap(NULL, 3495912, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) =
0x7f635f970000
mprotect(0x7f635fabc000, 2097152, PROT_NONE) = 0
mmap(0x7f635fcbc000, 20480, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x14c000) = 0x7f635fcbc000
mmap(0x7f635fcc1000, 18408, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f635fcc1000
close(3) = 0
open("/lib/libncurses.so.5", O_RDONLY) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0PP\1\0\0\0\0\0"..., 832)
= 832
fstat(3, {st_mode=S_IFREG|0755, st_size=329624, ...}) = 0
mmap(NULL, 2426888, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) =
0x7f635f71f000
mprotect(0x7f635f76b000, 2093056, PROT_NONE) = 0
mmap(0x7f635f96a000, 20480, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x4b000) = 0x7f635f96a000
mmap(0x7f635f96f000, 2056, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f635f96f000
close(3) = 0
open("/lib/libdl.so.2", O_RDONLY) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\360\r\0\0\0\0\0\0"...,
832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=14512, ...}) = 0
mmap(NULL, 2109696, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) =
0x7f635f51b000
mprotect(0x7f635f51d000, 2097152, PROT_NONE) = 0
mmap(0x7f635f71d000, 8192, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f635f71d000
close(3) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x7f6360378000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x7f6360377000
arch_prctl(ARCH_SET_FS, 0x7f63603776f0) = 0
mprotect(0x7f635f71d000, 4096, PROT_READ) = 0
mprotect(0x7f635f96a000, 16384, PROT_READ) = 0
mprotect(0x7f635fcbc000, 16384, PROT_READ) = 0
mprotect(0x7f635ff01000, 8192, PROT_READ) = 0
mprotect(0x7f636018b000, 4096, PROT_READ) = 0
mprotect(0x62e000, 4096, PROT_READ) = 0
mprotect(0x7f63603ab000, 4096, PROT_READ) = 0
munmap(0x7f636037a000, 189062) = 0
mmap(NULL, 233472, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x7f636033e000
rt_sigaction(SIGPROF, {0x7f635fa3ff30, ~[], SA_RESTORER|SA_RESTART,
0x7f635f9a20e0}, {SIG_DFL, [], 0}, 8) = 0
setitimer(ITIMER_PROF, {it_interval={0, 10000}, it_value={0, 10000}},
{it_interval={0, 0}, it_value={0, 0}}) = 0
mmap(NULL, 135168, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x7f636031d000
brk(0) = 0x8ab000
brk(0x8cc000) = 0x8cc000
stat("test.c", {st_mode=S_IFREG|0644, st_size=76, ...}) = 0
open("test.c", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=76, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x7f63603a8000
read(3, "#include <stdio.h>\n\nvoid main() "..., 4096) = 76
close(3) = 0
munmap(0x7f63603a8000, 4096) = 0
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++
Segmentation fault
=============================================================
$ gdb picoc
GNU gdb (Gentoo 7.2 p1) 7.2
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.gentoo.org/>...
Reading symbols from /home/Belliash/0/picoc/picoc...done.
(gdb) run test.c
Starting program: /home/Belliash/0/picoc/picoc test.c
Program received signal SIGSEGV, Segmentation fault.
0x0000000000411355 in ExpressionInfixOperator (Parser=0x7fffffffd650,
StackTop=0x7fffffffd3a0, Op=TokenAssign, BottomValue=0x7ffff7f6e1c0,
TopValue=0x7ffff7f6e210) at expression.c:711
711 else if (BottomValue->Typ->Base == TypePointer &&
IS_NUMERIC_COERCIBLE(TopValue))
(gdb)
Original comment by belli...@asiotec.org
on 23 Feb 2011 at 12:01
This can be architecture-independant as friend told me he also got this problem
on both computers. As you can see below one is 64bit, while the 2nd one is
32bit.
Linux host 2.6.37-gentoo #4 Mon Feb 21 16:33:08 CET 2011 i686 Intel(R)
Celeron(R) M processor 1.40GHz GenuineIntel GNU/Linux
Linux quad 2.6.37-gentoo #4 SMP Fri Feb 11 09:03:06 CET 2011 x86_64 Intel(R)
Core(TM)2 Quad CPU Q6600 @ 2.40GHz GenuineIntel GNU/Linux
Original comment by belli...@asiotec.org
on 23 Feb 2011 at 12:38
picoc test.c crashes my arm5/linux machine, too
Original comment by carlojpi...@gmail.com
on 27 May 2012 at 12:19
This is invalid program! GCC returns:
test.c: In function ‘main’:
test.c:7: error: invalid type argument of ‘unary *’ (have ‘int’)
Original comment by zahari.z...@gmail.com
on 28 May 2012 at 1:15
Original issue reported on code.google.com by
belli...@asiotec.org
on 19 Feb 2011 at 10:02