git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "René Scharfe" <l.s.r@web.de>
Cc: Git Mailing List <git@vger.kernel.org>,
	Lars Schneider <larsxschneider@gmail.com>
Subject: Re: [PATCH] convert: fix handling of dashless UTF prefix in validate_encoding()
Date: Sun, 06 Oct 2019 09:41:30 +0900	[thread overview]
Message-ID: <xmqqeezq66yt.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <c886671c-7753-6ac8-fefc-277e76019cd4@web.de> ("René Scharfe"'s message of "Fri, 4 Oct 2019 21:25:50 +0200")

René Scharfe <l.s.r@web.de> writes:

> Strip "UTF" and an optional dash from the start of 'upper' without
> passing a NULL pointer to skip_prefix() in the second call, as it cannot
> handle that.

Did the original meant to say "skip UTF- from the beginning of upper
and store it to stripped, or if that cannot be done, skip UTF from
the beginning of upper and store it to stripped", but made the
second one scan the stripped instead of upper by mistake?

Changing it to "skip UTF from upper and store it to stripped, and if
the resulting stripped begins with dash, advance stripped to skip
that too" is certainly a right fix.  Fixing the second one to scan
upper would also make the result correct, but there is no point
scanning the same thing twice to skip the same leading "UTF"
substring.

Thanks.

>
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
>  convert.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/convert.c b/convert.c
> index deb6f71b2d..25ac525d5f 100644
> --- a/convert.c
> +++ b/convert.c
> @@ -290,8 +290,8 @@ static int validate_encoding(const char *path, const char *enc,
>  			const char *stripped = NULL;
>  			char *upper = xstrdup_toupper(enc);
>  			upper[strlen(upper)-2] = '\0';
> -			if (!skip_prefix(upper, "UTF-", &stripped))
> -				skip_prefix(stripped, "UTF", &stripped);
> +			if (skip_prefix(upper, "UTF", &stripped))
> +				skip_prefix(stripped, "-", &stripped);
>  			advise(advise_msg, path, stripped);
>  			free(upper);
>  			if (die_on_error)
> @@ -310,8 +310,8 @@ static int validate_encoding(const char *path, const char *enc,
>  				"working-tree-encoding.");
>  			const char *stripped = NULL;
>  			char *upper = xstrdup_toupper(enc);
> -			if (!skip_prefix(upper, "UTF-", &stripped))
> -				skip_prefix(stripped, "UTF", &stripped);
> +			if (skip_prefix(upper, "UTF", &stripped))
> +				skip_prefix(stripped, "-", &stripped);
>  			advise(advise_msg, path, stripped, stripped);
>  			free(upper);
>  			if (die_on_error)
> --
> 2.23.0

      reply	other threads:[~2019-10-06  0:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-04 19:25 [PATCH] convert: fix handling of dashless UTF prefix in validate_encoding() René Scharfe
2019-10-06  0:41 ` Junio C Hamano [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqeezq66yt.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=l.s.r@web.de \
    --cc=larsxschneider@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).