Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: checking for overflow in C Message-ID: <10241@smoke.BRL.MIL> Date: 9 May 89 15:11:38 GMT References: <13367@dartvax.Dartmouth.EDU> <10218@smoke.BRL.MIL> <13003@haddock.ima.isc.com> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 9 In article <13003@haddock.ima.isc.com> karl@haddock.ima.isc.com (Karl Heuer) writes: >Let's take a concrete example. How do you think one should code the >implementation of the ANSI C function strtol(), which is required to detect >integer overflow and return ERANGE in this case? There's no requirement that strtol() be implemented in C, but assuming that you're trying to do so, in the loop that multiplies the accumulator by the base and adds in the next digit, before doing that operation test to see if it would overflow. It's not hard.