|
From: 张昭 <mai...@gm...> - 2012-02-23 09:59:45
|
Hi all:
I use
zhangzhao-debian:~/work/tests# /opt/valgrind-3.7.0/bin/valgrind --version
valgrind-3.7.0
to test follow code
#include <stdlib.h>
static int b[60];
int main ( int argc, char *argv[] )
{
int a[50];
int ret;
/*a[50] = 1;
a[51] = 1;*/
b[59] = 1;
b[60] = 2;
return EXIT_SUCCESS;
}
compile use gcc -g array.c -o array and run with
zhangzhao-debian:~/work/tests# /opt/valgrind-3.7.0/bin/valgrind
--tool=exp-sgcheck ./array
==14029== exp-sgcheck, a stack and global array overrun detector
==14029== NOTE: This is an Experimental-Class Valgrind Tool
==14029== Copyright (C) 2003-2011, and GNU GPL'd, by OpenWorks Ltd et al.
==14029== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==14029== Command: ./array
==14029==
==14029==
==14029== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
zhangzhao-debian:~/work/tests#
and I find this result; why? I always have a array out of bounds but
valgrind doesn't found that? Help
zhangzhao
|
|
From: Brian B. <bri...@gm...> - 2012-02-23 14:24:58
|
On Thu, Feb 23, 2012 at 1:59 AM, 张昭 <mai...@gm...> wrote:
> Hi all:
> I use
> zhangzhao-debian:~/work/tests# /opt/valgrind-3.7.0/bin/valgrind --version
> valgrind-3.7.0
> to test follow code
> #include <stdlib.h>
>
> static int b[60];
> int main ( int argc, char *argv[] )
> {
> int a[50];
> int ret;
> /*a[50] = 1;
> a[51] = 1;*/
> b[59] = 1;
> b[60] = 2;
> return EXIT_SUCCESS;
> }
> compile use gcc -g array.c -o array and run with
> zhangzhao-debian:~/work/tests# /opt/valgrind-3.7.0/bin/valgrind
> --tool=exp-sgcheck ./array
> ==14029== exp-sgcheck, a stack and global array overrun detector
> ==14029== NOTE: This is an Experimental-Class Valgrind Tool
> ==14029== Copyright (C) 2003-2011, and GNU GPL'd, by OpenWorks Ltd et al.
> ==14029== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
> ==14029== Command: ./array
> ==14029==
> ==14029==
> ==14029== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
> zhangzhao-debian:~/work/tests#
>
> and I find this result; why? I always have a array out of bounds but
> valgrind doesn't found that? Help
>
> zhangzhao
>
Try using the exp-sgcheck tool instead of memcheck.
Brian
|
|
From: Дмитрий Д. <di...@gm...> - 2012-02-23 16:33:20
|
With Fedora 16/x64 + V-trunk rev.12400/2261
gcc -O0 -g2 a.c -o array
valgrind --tool=exp-sgcheck ./array
i have:
- exp-sgcheck/globalerr works fine
- array: no errs about global array
- array: no errs about stack array
(fast) look into bugzilla shows no similar.
$ cat a.c
int b[60];
int main ( )
{
int a[60];
a[59] = 1;
a[60] = 2;
b[59] = 1;
b[60] = 2;
return 0;
}
$ gcc -O0 -g2 a.c -S -o /dev/tty
.file "a.c"
.text
.Ltext0:
.comm b,240,32
.globl main
.type main, @function
main:
.LFB0:
.file 1 "a.c"
.loc 1 3 0
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $120, %rsp
.loc 1 5 0
movl $1, -4(%rbp)
.loc 1 6 0
movl $2, 0(%rbp)
.loc 1 7 0
movl $1, b+236(%rip)
.loc 1 8 0
movl $2, b+240(%rip)
.loc 1 9 0
movl $0, %eax
.loc 1 10 0
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size main, .-main
[ skip ]
Dmitry
2012/2/23 张昭 <mai...@gm...>
> Hi all:
> I use
> zhangzhao-debian:~/work/tests# /opt/valgrind-3.7.0/bin/valgrind --version
> valgrind-3.7.0
> to test follow code
> #include <stdlib.h>
>
> static int b[60];
> int main ( int argc, char *argv[] )
> {
> int a[50];
> int ret;
> /*a[50] = 1;
> a[51] = 1;*/
> b[59] = 1;
> b[60] = 2;
> return EXIT_SUCCESS;
> }
> compile use gcc -g array.c -o array and run with
> zhangzhao-debian:~/work/tests# /opt/valgrind-3.7.0/bin/valgrind
> --tool=exp-sgcheck ./array
> ==14029== exp-sgcheck, a stack and global array overrun detector
> ==14029== NOTE: This is an Experimental-Class Valgrind Tool
> ==14029== Copyright (C) 2003-2011, and GNU GPL'd, by OpenWorks Ltd et al.
> ==14029== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
> ==14029== Command: ./array
> ==14029==
> ==14029==
> ==14029== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
> zhangzhao-debian:~/work/tests#
>
> and I find this result; why? I always have a array out of bounds but
> valgrind doesn't found that? Help
>
> zhangzhao
>
>
> ------------------------------------------------------------------------------
> Virtualization & Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> _______________________________________________
> Valgrind-users mailing list
> Val...@li...
> https://lists.sourceforge.net/lists/listinfo/valgrind-users
>
>
|
|
From: Philippe W. <phi...@sk...> - 2012-02-23 19:20:20
|
On Thu, 2012-02-23 at 17:59 +0800, 张昭 wrote:
>
>
> static int b[60];
> int main ( int argc, char *argv[] )
> {
> int a[50];
> int ret;
> /*a[50] = 1;
> a[51] = 1;*/
> b[59] = 1;
> b[60] = 2;
> return EXIT_SUCCESS;
> }
>
> and I find this result; why? I always have a array out of bounds
> but valgrind doesn't found that? Help
>
See in the user manual the description of the heuristic used by sgcheck.
http://www.valgrind.org/docs/manual/sg-manual.html#sg-manual.overview
section 11.3.
Basically, if the *same* instruction accesses first inside an array,
and then outside an array, then sgcheck will detect the array out of
bounds.
In the above case, each instruction is executed only once, and so
the heuristic cannot find it.
Philippe
|