Tool for detecting Array overflow

Discussion in 'C Programming' started by vashwath@rediffmail.com, Dec 8, 2005.

  1. Guest

    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, 2005
    #1
    1. Advertising

  2. 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.
     
    Chris McDonald, Dec 8, 2005
    #2
    1. Advertising

  3. Guest

    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, 2005
    #3
  4. 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
     
    =?ISO-8859-1?Q?Bj=F8rn_Augestad?=, Dec 8, 2005
    #4
  5. Guest

    > <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;


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

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

    a = 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, 2005
    #5
  6. [OT] Re: Tool for detecting Array overflow

    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;
    >
    >
    > for(i=0;i<10;i++)
    > printf("a[%d]= %d ",i,a);
    >
    > printf("\n");
    > printf("i=%d\n",i);
    >
    > a = 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
     
    =?ISO-8859-1?Q?Bj=F8rn_Augestad?=, Dec 8, 2005
    #6
  7. Guest

    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;
    >
    >
    > for(i=0;i<10;i++)
    > printf("a[%d]= %d ",i,a);
    >
    > printf("\n");
    > printf("i=%d\n",i);
    >
    > a = 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;


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

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

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

    }
     
    , Dec 8, 2005
    #7
  8. "" <> writes:

    > 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;
    > >
    > >
    > > for(i=0;i<10;i++)
    > > printf("a[%d]= %d ",i,a);
    > >
    > > printf("\n");
    > > printf("i=%d\n",i);
    > >
    > > a = 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
     
    Niklas Norrthon, Dec 8, 2005
    #8
  9. 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
     
    Igmar Palsenberg, Dec 8, 2005
    #9
  10. saurabh Guest

    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
     
    saurabh, Dec 8, 2005
    #10
  11. Guest

    Niklas Norrthon wrote:
    > "" <> writes:
    >
    > > 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;
    > > >
    > > >
    > > > for(i=0;i<10;i++)
    > > > printf("a[%d]= %d ",i,a);
    > > >
    > > > printf("\n");
    > > > printf("i=%d\n",i);
    > > >
    > > > a = 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, 2005
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Emmons

    Detecting overflow

    Paul Emmons, May 10, 2004, in forum: C Programming
    Replies:
    2
    Views:
    480
    Paul Emmons
    May 12, 2004
  2. dlamoris
    Replies:
    0
    Views:
    885
    dlamoris
    Oct 26, 2006
  3. Detecting multipication overflow

    , Nov 12, 2005, in forum: C Programming
    Replies:
    7
    Views:
    763
    jacob navia
    Dec 19, 2005
  4. detecting integer overflow

    , Dec 5, 2005, in forum: C Programming
    Replies:
    25
    Views:
    1,119
    RSoIsCaIrLiIoA
    Dec 18, 2005
  5. Ole Nielsby

    Detecting integer overflow

    Ole Nielsby, Sep 21, 2006, in forum: C++
    Replies:
    8
    Views:
    1,660
    Steve Pope
    Sep 22, 2006
Loading...

Share This Page