This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 2/4] Error on bad count number
- From: Joel Brobecker <brobecker at adacore dot com>
- To: Pedro Alves <palves at redhat dot com>
- Cc: Yao Qi <yao at codesourcery dot com>, gdb-patches at sourceware dot org
- Date: Thu, 6 Mar 2014 05:24:10 -0800
- Subject: Re: [PATCH 2/4] Error on bad count number
- Authentication-results: sourceware.org; auth=none
- References: <1394023608-10761-1-git-send-email-yao at codesourcery dot com> <1394023608-10761-3-git-send-email-yao at codesourcery dot com> <20140305142939 dot GB16858 at adacore dot com> <531749BA dot 8050806 at redhat dot com> <5318456D dot 3010709 at codesourcery dot com> <53186842 dot 9030704 at redhat dot com>
> 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