Re: avoid atoi, when possible; int overflow -> heap corruption
- From
- Morten Welinder <mwelinder@gmail.com>
- Date
- May 22, 2006, 13:16 UTC
- Message-ID
- <118833cc0605220616t75a182b1oa404d5efe8a1f5d9@mail.gmail.com>
- In-Reply-To
- <871wumim28.fsf_-_@rho.meyering.net>
> There are about 20 uses of atoi, and most calls can return > a usable result in spite of an invalid input -- just because > atoi returns the same thing for "99" as "99-and-any-suffix". > It would be better not to ignore invalid inputs.
atoi has undefined behaviour for "99-and-any-suffix". You might get lucky and get back 99, but you might also get a random value or a core dump.
Morten