Re: mark parsing in fast-import
- From
Shawn O. Pearce <spearce@spearce.org>
- Date
- Apr 21, 2008, 00:26 UTC
- Message-ID
- <20080421002626.GJ29771@spearce.org>
- In-Reply-To
- <20080420234438.GC12865@alea.gnuu.de>
Jrg Sommer <joerg@alea.gnuu.de> wrote:
Show 22 quoted lines
> >
> > Uh, that's a bug in fast-import. ":4abc" is _not_ a mark if you
> > read the language specification. Only ":4" is a mark. So we are
> > accepting crap and reading it in odd ways. Not good.
>
> What about this:
>
> diff --git a/fast-import.c b/fast-import.c
> index 73e5439..f60e4ab 100644
> --- a/fast-import.c
> +++ b/fast-import.c
> @@ -1690,10 +1690,31 @@ static void skip_optional_lf(void)
> ungetc(term_char, stdin);
> }
>
> +static inline int parse_mark(const const char *str, uintmax_t* mark,
> + char **after_mark)
> +{
> + if (!str || str[0] != ':' || !isdigit(str[1]))
> + return 1;
> +
> + char *am;Although we conform to mostly C99 style, variables should be declared at the top of the scope and not after a statement.
Show 18 quoted lines
> + const uintmax_t m = strtoumax(&str[1], &am, 10);
> + if (errno == 0) {
> + *mark = m;
> + *after_mark = am;
> + return 0;
> + }
> + return 1;
> +}
> +
> static void cmd_mark(void)
> {
> - if (!prefixcmp(command_buf.buf, "mark :")) {
> - next_mark = strtoumax(command_buf.buf + 6, NULL, 10);
> + uintmax_t mark = 0;
> + char *after_mark = NULL;
> +
> + if (!prefixcmp(command_buf.buf, "mark ") &&
> + parse_mark(&command_buf.buf[5], &mark, &after_mark) &&Hmm. Shouldn't this be ! parse_mark given that it returns 0 on success and 1 on failure?
-- Shawn.