Path: csiph.com!2.us.feeder.erje.net!feeder.erje.net!2.eu.feeder.erje.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!buffer1.nntp.ams1.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail NNTP-Posting-Date: Sat, 29 Apr 2017 08:57:52 -0500 From: Gareth Owen Newsgroups: comp.lang.c Subject: Re: Is this code considered to transgress the signed overflow purism? References: <11ea6682-cdee-4513-97c2-6c90b585716a@googlegroups.com> <87o9vi6rql.fsf@bsb.me.uk> <26aee5e9-ed2f-4c6e-af68-b85418c7e641@googlegroups.com> <10c71913-2871-4474-b05c-804bfdb7074d@googlegroups.com> <11b1eeab-5835-43cc-a789-41305845abbc@googlegroups.com> Date: Sat, 29 Apr 2017 14:57:52 +0100 Message-ID: <87y3ujpb8f.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Cancel-Lock: sha1:V23K+V6LhXvtdBwo7A75wVQnv48= MIME-Version: 1.0 Content-Type: text/plain Lines: 16 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-yJZuPgyIPp2wBd49Fd4mCAwrLEm2+IShIwmhcq7sQMBEKrT5VekXemJS8Y5kBsumEeadcb0nEXJCW64!ZEH1pJCEhIL1qUlKfE5wsX0C8ZLJB3PloJ8iQW0cjNilfbQoNnHz9yjjh4xsA4AA8aMriCc= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 1928 Xref: csiph.com comp.lang.c:108733 Malcolm McLean writes: > int buffsize = width * height; // uh oh. UB here, can't do that If only * had some sort of inverse operation we could use to check whether width*height > INT_MAX Lets pretend theres an operator called \ that does inverse-multiplication. Then we could write if(width <= INT_MAX \ height) { // No UB!! } But without that operator, we're definitely stuck with casting everything to doubles.