Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer,comp.lang.c Subject: Re: Arithmetic overflow checking Date: Sun, 10 Jul 2011 09:28:50 -0400 Organization: A noiseless patient Spider Lines: 21 Message-ID: References: <015aeb15-57db-48ab-9cd4-77f8448b632f@w24g2000yqw.googlegroups.com> <2rydnez7l-H5BYnTnZ2dnUVZ_vGdnZ2d@earthlink.com> <9LWdnZH2hdfmyYvTnZ2dnUVZ_vidnZ2d@posted.palinacquisition> <3797038f-22d1-40b2-8c12-60db5a0976b8@t5g2000yqj.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 10 Jul 2011 13:29:33 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="BrOwaJANne849xlH+KPYjQ"; logging-data="19694"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19oW1/co68M8Ppg04UiTtPO" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.18) Gecko/20110616 Thunderbird/3.1.11 In-Reply-To: Cancel-Lock: sha1:qFsUiJ1w3LacPG0L8aN/p6v3dTc= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6043 comp.lang.c:8068 On 7/10/2011 5:47 AM, China Blue Dolls wrote: > > In C the array size is not part of the type or value, so there is nothing to > check. No; the size (element count) is part of an array's type. Your compiler will confirm this for you by issuing a diagnostic for char matrix[5][7]; /* five char[7] arrays */ char (*nine)[9]; /* pointer to char[9] */ nine = matrix; /* point it at the first char[7] */ > C integer arithmetic is always modulo M, for some large M (like 2**32 or 2**64). > So the concept of overflow does not apply. This is true only for `unsigned' integer arithmetic. Signed integer arithmetic is in fact vulnerable to overflow. -- Eric Sosman esosman@ieee-dot-org.invalid