3 ms·
To be fair, I'd reroll atoi too - but only once, with "sufficient" unit tests (e.g. round trip unit tests for INT_MIN..INT_MAX), and only because atoi has no pr
by MaulingMonkey 10y ago
To be fair, I'd reroll atoi too - but only once, with "sufficient" unit tests (e.g. round trip unit tests for INT_MIN..INT_MAX), and only because atoi has no proper error checking nor wchar_t* variants.
- kazinator 10y agoIndeed; atoi in fact invokes undefined behavior in out of range situations; you can only safely use it when the input has been lexically analyzed to be a valid integer of only so many digits as not to overflow. I'd tend to make this re-rolled atoi a wrapper around strtol/wcstol.
- MaulingMonkey 10y ago> atoi in fact invokes undefined behavior in out of range situations Ouch! TIL. You'd think by now I wouldn't be surprised by such things, and yet, somehow I was...