Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #13834 > unrolled thread
| Started by | sailer <xiangdong.ji@gmail.com> |
|---|---|
| First post | 2011-11-23 20:25 -0800 |
| Last post | 2011-11-29 19:46 -0800 |
| Articles | 5 on this page of 25 — 13 participants |
Back to article view | Back to comp.lang.c
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
Page 2 of 2 — ← Prev page 1 [2]
| From | pete <pfiland@mindspring.com> |
|---|---|
| Date | 2011-11-28 18:59 -0500 |
| Message-ID | <4ED42047.4557@mindspring.com> |
| In reply to | #13998 |
sailer wrote: > is it safe enough? No. > int words; > ovf(words, sizeof(int), &bytes, &overflow); (words) should be initialized before its value is passed to ovf(). -- pete
[toc] | [prev] | [next] | [standalone]
| From | sailer <xiangdong.ji@gmail.com> |
|---|---|
| Date | 2011-11-29 19:44 -0800 |
| Message-ID | <f8fc761c-218b-4372-b5e5-9b92789bc815@cc2g2000vbb.googlegroups.com> |
| In reply to | #14015 |
On Nov 29, 7:59 am, pete <pfil...@mindspring.com> wrote: > sailer wrote: > > is it safe enough? > > No. > > > int words; > > ovf(words, sizeof(int), &bytes, &overflow); > > (words) should be initialized > before its value is passed to ovf(). > > -- > pete It's a demo code fragment, I checked the asm code to figure out whether the overflow detection works, and the type of bytes should be 'unsigned int', it was a typo error and I tried to post a correction but failed.
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Date | 2011-11-30 11:08 -0500 |
| Message-ID | <4ED654E9.8050804@verizon.net> |
| In reply to | #14060 |
On 11/29/2011 10:44 PM, sailer wrote: > On Nov 29, 7:59 am, pete <pfil...@mindspring.com> wrote: >> sailer wrote: >>> is it safe enough? >> >> No. >> >>> int words; >>> ovf(words, sizeof(int), &bytes, &overflow); >> >> (words) should be initialized >> before its value is passed to ovf(). >> >> -- >> pete > > It's a demo code fragment, I checked the asm code to figure out > whether the overflow detection works, Let that be a lesson: even "demo code fragments" should have defined behavior; if they don't, your test becomes meaningless.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2011-11-30 09:01 -0800 |
| Message-ID | <lnobvtr1d1.fsf@nuthaus.mib.org> |
| In reply to | #14079 |
James Kuyper <jameskuyper@verizon.net> writes:
> On 11/29/2011 10:44 PM, sailer wrote:
>> On Nov 29, 7:59 am, pete <pfil...@mindspring.com> wrote:
>>> sailer wrote:
>>>> is it safe enough?
>>>
>>> No.
>>>
>>>> int words;
>>>> ovf(words, sizeof(int), &bytes, &overflow);
>>>
>>> (words) should be initialized
>>> before its value is passed to ovf().
>>>
>>> --
>>> pete
>>
>> It's a demo code fragment, I checked the asm code to figure out
>> whether the overflow detection works,
>
> Let that be a lesson: even "demo code fragments" should have defined
> behavior; if they don't, your test becomes meaningless.
Right. If your code has undefined behavior, an optimizing compiler is
permitted to transform it in ways that depend on the assumption that the
behavior is defined.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
[toc] | [prev] | [next] | [standalone]
| From | sailer <xiangdong.ji@gmail.com> |
|---|---|
| Date | 2011-11-29 19:46 -0800 |
| Message-ID | <9ac80553-efe4-45e9-828d-6d4293100ab5@q11g2000vbq.googlegroups.com> |
| In reply to | #13834 |
On Nov 24, 12:25 pm, sailer <xiangdong...@gmail.com> wrote:
> Hi,
>
> I have the following code which was used to check whether the result
> of (a * b) is larger than the maximum integer value.
>
> ovf(int a, int b, int *r, int *v)
> {
> *r = a * b;
> if (b == 0 || a == *r / b)
> *v = 0;
> else
> *v = 1;
>
> }
>
> int main()
> {
> int words;
> int bytes;
> int overflow;
>
> //... whatever
> ovf(words, sizeof(int), &bytes, &overflow);
> if (overflow)
> printf("overflow");
>
> }
>
> It doesn't work with GCC 4.5.2 if enabling -O2 or -O3, asm code
> generated by GCC is as follows, call to ovf is eliminated, seems that
> GCC evaluates (a == *r/b) to TRUE at compile time, is there anyway to
> revise ovf to let it satisfy GCC? thanks in advance.
>
> main:
> pushl %ebp #
> xorl %eax, %eax #
> movl %esp, %ebp #,
> popl %ebp #
> ret
> .size main, .-main
> .ident "GCC: (GNU) 4.5.2"
> .section .note.GNU-stack,"",@progbits
BTW. Thanks all for helping solving the problem, and sorry that I also
posted the same question to comp.lang.c++ without the knowledge of
cross-post.
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.c
csiph-web