Re: [PATCH 2/4] Error on bad count number

Joel Brobecker
2014-03-06T13:24:16Z

> I think that what exact number is used for error return
> is mostly irrelevant. The interface of get_number's value
> return alone is just not sufficient as is. Not changing
> the prototype, we could e.g. in addition of checking for
> zero return, have the callers check whether the passed in
> char pointer pointer advanced (and make sure get_number
> doesn't advance the pointer on invalid input). So the
> correct use becomes:
>
> p = arg;
> num = get_number (&p);
> if (num == 0 && p == arg)
> error (_("Bad number: '%s'"), arg);
>
> Sort of like strtol vs itoa.

There are not so many calls to that routine or (get_number_trailer),
so I think it would be easy to change the interface. But better yet,
why not throw an error? Most of the current uses just throw an error
right after when the returned value was 0. There are some uses where
there is no error handling, but I think they need to be reviewed as
they could actually benefit from it. After a quick glance, it wasn't
obvious to me whether there was a hole in the implementation or not.

--
Joel