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

Pedro Alves
2014-03-06T12:21:32Z

On 03/06/2014 09:52 AM, Yao Qi wrote:
> On 03/05/2014 11:58 PM, Pedro Alves wrote:
>> I had the same thought. I wondered whether 0 was meant to
>> remove the enable count, but the docs don't say anything
>> about it. Is there another way to disable the count, and
>> bring back the disposition to enabled? If not, I wonder
>> whether using 0 for that would be a good idea?
>
> If 0 is potentially acceptable, I am fine to keep it. I'll back
> to change get_number to return negative for invalid input, to
> differentiate valid number zero and invalid input.

AFAICS, get_number handles negative numbers. E.g.,

(top-gdb) ignore -6 1
Will ignore next crossing of breakpoint -6.

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.

--
Pedro Alves