Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #14040

Re: check integer overflow with GCC 4.5.2

From 88888 Dihedral <dihedral88888@googlemail.com>
Newsgroups comp.lang.c
Subject Re: check integer overflow with GCC 4.5.2
Date 2011-11-29 06:28 -0800
Organization http://groups.google.com
Message-ID <5845511.396.1322576921182.JavaMail.geo-discussion-forums@prgi20> (permalink)
References (1 earlier) <4ECDDA82.4C71@mindspring.com> <af78722e-ed85-4f3c-a721-8f4786f22cd6@m7g2000vbc.googlegroups.com> <op.v5f1pcaplahckh@cantereyd> <3cb8bc00-3c7e-452d-a97c-dab639049df1@f36g2000prj.googlegroups.com> <jb2lnp$40u$1@dont-email.me>

Show all headers | View raw


On Tuesday, November 29, 2011 9:12:29 PM UTC+8, Noob wrote:
> sailer wrote:
> 
> > Here is the c code and asm code of main, call to 'ovf' is
> > eliminated by compiler :
> > 
> > #include <stdio.h>
> > #include <limits.h>
> > 
> > void
> > ovf(int a, int b, int *v)
> > {
> >         if (b == 0 || (INT_MAX/b >= a))
> >                 *v = 0;
> >         else
> >                 *v = 1;
> > }
> > 
> > int main ()
> > {
> >         int words;
> >         int overflow;
> > 
> >         ovf(words, sizeof(int), &overflow);
> >         if (overflow)
> >                 printf("overflow\n");
> > 
> >         return 0;
> > }
> > 
> > main:
> >         pushl   %ebp
> >         xorl    %eax, %eax
> >         movl    %esp, %ebp
> >         subl    $8, %esp
> >         leave
> >         ret
> >         .size   main, .-main
> >         .ident  "GCC: (GNU) 4.5.2"
> >         .section        .note.GNU-stack,"",@progbits
> > 
> > 
> > command line : gcc -O3 -m32 -msse2 a.c -S
> 
> $ cat ovf.c
> #include <limits.h>
> int mul_overflow(int a, int b)
> {
>   return b && a > INT_MAX/b;
> }
> 
> $ gcc -S -O3 -Wall -Wextra ovf.c
> $ cat ovf.s
>         .file   "ovf.c"
>         .text
>         .p2align 4,,15
> .globl _mul_overflow
>         .def    _mul_overflow;  .scl    2;      .type   32;     .endef
> _mul_overflow:
>         pushl   %ebp
>         xorl    %eax, %eax
>         movl    %esp, %ebp
>         movl    12(%ebp), %ecx
>         testl   %ecx, %ecx
>         je      L2
>         movl    $2147483647, %eax
>         movl    %eax, %edx
>         sarl    $31, %edx
>         idivl   %ecx
>         cmpl    8(%ebp), %eax
>         setl    %al
>         movzbl  %al, %eax
> L2:
>         popl    %ebp
>         ret

If I know the push down types of all arguments in a function in  C in a platform, it is trivial to pick all those well packed arguments in the stack in a rcver after a long or a short jump. That assumes that callers pushes everything right down the stack or the heap. 

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

check integer overflow with GCC 4.5.2 sailer <xiangdong.ji@gmail.com> - 2011-11-23 20:25 -0800
  Re: check integer overflow with GCC 4.5.2 pete <pfiland@mindspring.com> - 2011-11-24 00:47 -0500
    Re: check integer overflow with GCC 4.5.2 sailer <xiangdong.ji@gmail.com> - 2011-11-23 22:29 -0800
      Re: check integer overflow with GCC 4.5.2 "Philip Lantz" <prl@canterey.us> - 2011-11-24 01:23 -0800
        Re: check integer overflow with GCC 4.5.2 sailer <xiangdong.ji@gmail.com> - 2011-11-27 23:14 -0800
          Re: check integer overflow with GCC 4.5.2 James Kuyper <jameskuyper@verizon.net> - 2011-11-28 07:04 -0500
          Re: check integer overflow with GCC 4.5.2 Noob <root@127.0.0.1> - 2011-11-29 14:12 +0100
            Re: check integer overflow with GCC 4.5.2 Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-11-29 16:16 +0200
            Re: check integer overflow with GCC 4.5.2 88888 Dihedral <dihedral88888@googlemail.com> - 2011-11-29 06:28 -0800
  Re: check integer overflow with GCC 4.5.2 Robert Wessel <robertwessel2@yahoo.com> - 2011-11-24 00:28 -0600
  Re: check integer overflow with GCC 4.5.2 Vincenzo Mercuri <vincenzo.mercuri@yahoo.it> - 2011-11-24 09:46 +0100
    Re: check integer overflow with GCC 4.5.2 sailer <xiangdong.ji@gmail.com> - 2011-11-24 01:08 -0800
      Re: check integer overflow with GCC 4.5.2 "Philip Lantz" <prl@canterey.us> - 2011-11-24 01:26 -0800
        Re: check integer overflow with GCC 4.5.2 sailer <xiangdong.ji@gmail.com> - 2011-11-27 23:09 -0800
    Re: check integer overflow with GCC 4.5.2 "io_x" <a@b.c.invalid> - 2011-11-24 14:19 +0100
  Re: check integer overflow with GCC 4.5.2 gwowen <gwowen@gmail.com> - 2011-11-24 09:10 -0800
  Re: check integer overflow with GCC 4.5.2 sailer <xiangdong.ji@gmail.com> - 2011-11-27 23:21 -0800
    Re: check integer overflow with GCC 4.5.2 Keith Thompson <kst-u@mib.org> - 2011-11-28 16:31 -0800
      Re: check integer overflow with GCC 4.5.2 Ian Collins <ian-news@hotmail.com> - 2011-11-29 13:53 +1300
  Re: check integer overflow with GCC 4.5.2 sailer <xiangdong.ji@gmail.com> - 2011-11-27 23:34 -0800
    Re: check integer overflow with GCC 4.5.2 pete <pfiland@mindspring.com> - 2011-11-28 18:59 -0500
      Re: check integer overflow with GCC 4.5.2 sailer <xiangdong.ji@gmail.com> - 2011-11-29 19:44 -0800
        Re: check integer overflow with GCC 4.5.2 James Kuyper <jameskuyper@verizon.net> - 2011-11-30 11:08 -0500
          Re: check integer overflow with GCC 4.5.2 Keith Thompson <kst-u@mib.org> - 2011-11-30 09:01 -0800
  Re: check integer overflow with GCC 4.5.2 sailer <xiangdong.ji@gmail.com> - 2011-11-29 19:46 -0800

csiph-web