By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,134 Members | 1,942 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,134 IT Pros & Developers. It's quick & easy.

Tool for detecting Array overflow

P: n/a
Hi all,
Is there any free tool available for detecting array overflow? I found
one which detects overflow of dynamic arrays. But I need a tool(or a
special compiler) which detects static array overflows too.

Thanks

Dec 8 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
va******@rediffmail.com writes:
Hi all,
Is there any free tool available for detecting array overflow? I found
one which detects overflow of dynamic arrays. But I need a tool(or a
special compiler) which detects static array overflows too.


<OT>
Any helpful answer you receive will probably be very compiler-specific.
If using gcc, your instance of it may support the -fbounds-check
command line option.
</OT>

--
Chris.
Dec 8 '05 #2

P: n/a
va******@rediffmail.com wrote:
Hi all,
Is there any free tool available for detecting array overflow? I found
one which detects overflow of dynamic arrays. But I need a tool(or a
special compiler) which detects static array overflows too.


Just do what your teachers always tell you to do. Check your bounds
before using the array.

Dec 8 '05 #3

P: n/a
va******@rediffmail.com wrote:
Hi all,
Is there any free tool available for detecting array overflow? I found
one which detects overflow of dynamic arrays. But I need a tool(or a
special compiler) which detects static array overflows too.

Thanks


On linux you can use valgrind, http://valgrind.kde.org.
Bjørn
Dec 8 '05 #4

P: n/a
> <OT>
Any helpful answer you receive will probably be very compiler-specific.
If using gcc, your instance of it may support the -fbounds-check
command line option.
</OT>

Thanks for replying Chris.

Yes, I am using gcc for compilation.
I used the options you suggested for the following program

#include <stdio.h>

int main()
{
int a[10];

int i;

for(i=0;i<10;i++)
a[i] = i;
for(i=0;i<10;i++)
printf("a[%d]= %d ",i,a[i]);

printf("\n");
printf("i=%d\n",i);

a[i] = 10;/*Array overflow???*/

}

I gave the following command
gcc -w -Wall -fbounds-check arrBound.c

But it did not detect the overflow.
Am i using the options correctly.

Dec 8 '05 #5

P: n/a
va******@rediffmail.com wrote:
<OT>
Any helpful answer you receive will probably be very compiler-specific.
If using gcc, your instance of it may support the -fbounds-check
command line option.
</OT>

Thanks for replying Chris.

Yes, I am using gcc for compilation.
I used the options you suggested for the following program

#include <stdio.h>

int main()
{
int a[10];

int i;

for(i=0;i<10;i++)
a[i] = i;
for(i=0;i<10;i++)
printf("a[%d]= %d ",i,a[i]);

printf("\n");
printf("i=%d\n",i);

a[i] = 10;/*Array overflow???*/

}

I gave the following command
gcc -w -Wall -fbounds-check arrBound.c

But it did not detect the overflow.
Am i using the options correctly.

Check the gcc man page for details regarding -fbounds-check. I have gcc
4.0.2 prerelease 20050901 (SUSE 10), and my man page states that
-fbounds-check works for fortran and java only.

Bjørn
Dec 8 '05 #6

P: n/a
va******@rediffmail.com wrote:
<OT>
Any helpful answer you receive will probably be very compiler-specific.
If using gcc, your instance of it may support the -fbounds-check
command line option.
</OT>

Thanks for replying Chris.

Yes, I am using gcc for compilation.
I used the options you suggested for the following program

#include <stdio.h>

int main()
{
int a[10];

int i;

for(i=0;i<10;i++)
a[i] = i;
for(i=0;i<10;i++)
printf("a[%d]= %d ",i,a[i]);

printf("\n");
printf("i=%d\n",i);

a[i] = 10;/*Array overflow???*/

}

I gave the following command
gcc -w -Wall -fbounds-check arrBound.c

But it did not detect the overflow.
Am i using the options correctly.


In your code, I never exceed 9. So it did not detect overflow because
there is no overflow. Just modify it with the following to cause
overflow:

int main()
{
int a[10];

int i;

for(i=0;i<10;i++)
a[i] = i;
for(i=0;i<10;i++)
printf("a[%d]= %d ",i,a[i]);

printf("\n");
printf("i=%d\n",i);

i++; /*Cause overflow!*/
a[i] = 10;/*Array overflow???*/

}

Dec 8 '05 #7

P: n/a
"sl*******@yahoo.com" <sl*******@gmail.com> writes:
va******@rediffmail.com wrote:

Yes, I am using gcc for compilation.
I used the options you suggested for the following program

#include <stdio.h>

int main()
{
int a[10];

int i;

for(i=0;i<10;i++)
a[i] = i;
for(i=0;i<10;i++)
printf("a[%d]= %d ",i,a[i]);

printf("\n");
printf("i=%d\n",i);

a[i] = 10;/*Array overflow???*/

}

I gave the following command
gcc -w -Wall -fbounds-check arrBound.c

But it did not detect the overflow.
Am i using the options correctly.


In your code, I never exceed 9. So it did not detect overflow because
there is no overflow. Just modify it with the following to cause
overflow:


If that is the case, could you explain why the last printf
statement outputs "i=10"?

/Niklas Norrthon
Dec 8 '05 #8

P: n/a
Bjørn Augestad wrote:
On linux you can use valgrind, http://valgrind.kde.org.


Which doesn't detect overflows of arrays located on the stack.

Igmar
Dec 8 '05 #9

P: n/a
Hi,

Try with this code: file name overflow.c

#include <stdlib.h>
#include <stdio.h>

int main ()
{
int arr[2] = {2,3,4};
}

On compiling with gcc version 3.4.2, I can see following compilation
error message,
gcc -fbounds-check overflow.c
overflow.c: In function `main':
overflow.c:6: warning: excess elements in array initializer
overflow.c6: warning: (near initialization for `arr')

Thanks & Regards,
Saurabh.
Igmar Palsenberg wrote:
Bjørn Augestad wrote:
On linux you can use valgrind, http://valgrind.kde.org.


Which doesn't detect overflows of arrays located on the stack.



Igmar


Dec 8 '05 #10

P: n/a
Niklas Norrthon wrote:
"sl*******@yahoo.com" <sl*******@gmail.com> writes:
va******@rediffmail.com wrote:

Yes, I am using gcc for compilation.
I used the options you suggested for the following program

#include <stdio.h>

int main()
{
int a[10];

int i;

for(i=0;i<10;i++)
a[i] = i;
for(i=0;i<10;i++)
printf("a[%d]= %d ",i,a[i]);

printf("\n");
printf("i=%d\n",i);

a[i] = 10;/*Array overflow???*/

}

I gave the following command
gcc -w -Wall -fbounds-check arrBound.c

But it did not detect the overflow.
Am i using the options correctly.


In your code, I never exceed 9. So it did not detect overflow because
there is no overflow. Just modify it with the following to cause
overflow:


If that is the case, could you explain why the last printf
statement outputs "i=10"?


Ah, sorry, I missed the fact that the i++ in the for loop does indeed
increment i to 10.

Dec 8 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.