folks,
I can't grep this program. I do not know why... Any ideas?
On 7 November 2014 05:49, Dimitris Papastamos <sin_AT_2f30.org> wrote:
> On Fri, Nov 07, 2014 at 11:40:03AM +0100, k0ga_AT_shike2.com wrote:
>>
>> >> > * Use strtonum() or estrtol() from sbase instead of atoi().
>> >>
>> >> I agree here if the string comes from the user. If the string
>> >> is an internal string then there is no problem with atoi.
>> >
>> > It is generally unlikely that the string has been validated to
>> > be an integer before getting to atoi(). With atoi() you cannot
>> > distinguish between an invalid integer and 0.
>>
>> There are a lot of cases where it is validated, for example
>> if you used first a regular expression to filter lines. There
>> are also a lot of uses where doesn't mind the difference
>> between 0 and no integer (for example sort -n). There
>> are also a lot of cases where 0 is not a valid value.
>>
>> > Generally speaking, it should never be used.
>>
>> 'should never be used' is not a very general sentence.
>>
>> But, ok. This is a personal taste (this and the other question
>> about strlcpy), and I don't want to begin a war.
>
> BTW, just to clarify, strtol() and friends has its set of problems
> as well. It is too elaborate to check for error conditions unless
> you already have a wrapper to do this once.
>
> strtonum() is I think the most appropriate interface to default to
> and perhaps switch over to atoi() when you are aware of its limitations
> and they do not impact the correctness of your code.
>
Received on Fri Nov 07 2014 - 19:28:58 CET
This archive was generated by hypermail 2.3.0
: Fri Nov 07 2014 - 19:36:08 CET