473,378 Members | 1,434 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Tool for detecting Array overflow

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
10 3240
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
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
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
> <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
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
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
"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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Karthik | last post by:
Hi, I am writing this application that needs a lot of arithmetic calculations. I was wondering if C++ language specifies any way of detecting arithmetic overflows. Let us consider the following...
2
by: Paul Emmons | last post by:
Can anyone suggest example code, or how to proceed, in adding or subtracting two long long integers (I'm working in gcc with Linux, where a long long is 64 bits) and determining whether an overflow...
1
by: dati_remo | last post by:
Which is the best tool for discover buffer overflow, both for static array and array allocated with malloc, during debugging? What about Rational Purify? Someone can give a good advice? ...
29
by: shmartonak | last post by:
For maximum portability what should the type of an array index be? Can any integer type be used safely? Or should I only use an unsigned type? Or what? If I'm using pointers to access array...
7
by: wij | last post by:
Hi: Is there better way of detecting multiplication overflow for type long than by using double precision of lldiv to verify the result? Thanks in advance. I.J.Wang
25
by: junky_fellow | last post by:
Is there any way by which the overflow during addition of two integers may be detected ? eg. suppose we have three unsigned integers, a ,b, c. we are doing a check like if ((a +b) > c) do...
7
by: pocmatos | last post by:
Hi all, What the best way to detect under/over flow in a program with a lot of computations? For example: #include <iostream> #include <limits> using namespace std;
8
by: Ole Nielsby | last post by:
Given two longs: long a = ...; long b = ...; What's the simplest/fastest way of performing a simple operation on longs and detecting overflow? long c = a + b; // but branch on overflow
6
by: Andre Majorel | last post by:
How do you compute an off_t with overflow detection ? Ideally, the target language is C89/C90 and the target platform is reasonably recent versions of the major Unixen. If there is no practical...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.