Re: Exceeding limits during arithmetic
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Tue, 12 Jun 2007 18:46:48 -0400
Mike Aubury wrote:
Is there any standard (or even non-standard) way to detect limit
overflow in arithmetic in C ?
eg.
/* assuming 4 byte ints.. */
int a=2147483647;
int b=2147483647;
int c;
c=a*b;
if (INT_MAX / b < a) overflow();
else c = a * b;
and #include <limits.h>. Diddle to handle -ve input values.
--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
<http://kadaitcha.cx/vista/dogsbreakfast/index.html>
cbfalconer at maineline dot net
--
Posted via a free Usenet account from http://www.teranews.com
.
- References:
- Exceeding limits during arithmetic
- From: Mike Aubury
- Exceeding limits during arithmetic
- Prev by Date: Re: Fight Stopping AIDS, Let's Do it...
- Next by Date: Re: Exceeding limits during arithmetic
- Previous by thread: Re: Exceeding limits during arithmetic
- Next by thread: Re: Query:how to use windows api in my c source code?
- Index(es):
Relevant Pages
|