Re: mark parsing in fast-import

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jrg Sommer <joerg@xxxxxxxxxxxx> wrote:
> > 
> > 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.

> +	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.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux