git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / Atom feed
* [PATCH] convert: fix handling of dashless UTF prefix in validate_encoding()
@ 2019-10-04 19:25 René Scharfe
  2019-10-06  0:41 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2019-10-04 19:25 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano, Lars Schneider

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.

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] convert: fix handling of dashless UTF prefix in validate_encoding()
  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
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2019-10-06  0:41 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git Mailing List, Lars Schneider

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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

git@vger.kernel.org list mirror (unofficial, one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git