{"thread":{"id":"51971","subject":"[PATCH] convert: fix handling of dashless UTF prefix in validate_encoding()","startedAt":"2019-10-04T19:26:00Z","lastAt":"2019-10-06T00:41:41Z","messageCount":2,"participants":["René Scharfe","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"383440","messageId":"c886671c-7753-6ac8-fefc-277e76019cd4@web.de","threadId":"51971","inReplyTo":null,"subject":"[PATCH] convert: fix handling of dashless UTF prefix in validate_encoding()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2019-10-04T19:25:50Z","receivedAt":"2019-10-04T19:26:00Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Strip \"UTF\" and an optional dash from the start of 'upper' without\npassing a NULL pointer to skip_prefix() in the second call, as it cannot\nhandle that.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n convert.c | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/convert.c b/convert.c\nindex deb6f71b2d..25ac525d5f 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -290,8 +290,8 @@ static int validate_encoding(const char *path, const char *enc,\n \t\t\tconst char *stripped = NULL;\n \t\t\tchar *upper = xstrdup_toupper(enc);\n \t\t\tupper[strlen(upper)-2] = '\\0';\n-\t\t\tif (!skip_prefix(upper, \"UTF-\", &stripped))\n-\t\t\t\tskip_prefix(stripped, \"UTF\", &stripped);\n+\t\t\tif (skip_prefix(upper, \"UTF\", &stripped))\n+\t\t\t\tskip_prefix(stripped, \"-\", &stripped);\n \t\t\tadvise(advise_msg, path, stripped);\n \t\t\tfree(upper);\n \t\t\tif (die_on_error)\n@@ -310,8 +310,8 @@ static int validate_encoding(const char *path, const char *enc,\n \t\t\t\t\"working-tree-encoding.\");\n \t\t\tconst char *stripped = NULL;\n \t\t\tchar *upper = xstrdup_toupper(enc);\n-\t\t\tif (!skip_prefix(upper, \"UTF-\", &stripped))\n-\t\t\t\tskip_prefix(stripped, \"UTF\", &stripped);\n+\t\t\tif (skip_prefix(upper, \"UTF\", &stripped))\n+\t\t\t\tskip_prefix(stripped, \"-\", &stripped);\n \t\t\tadvise(advise_msg, path, stripped, stripped);\n \t\t\tfree(upper);\n \t\t\tif (die_on_error)\n--\n2.23.0\n"},{"id":"383507","messageId":"xmqqeezq66yt.fsf@gitster-ct.c.googlers.com","threadId":"51971","inReplyTo":"c886671c-7753-6ac8-fefc-277e76019cd4@web.de","subject":"Re: [PATCH] convert: fix handling of dashless UTF prefix in validate_encoding()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-10-06T00:41:30Z","receivedAt":"2019-10-06T00:41:41Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"René Scharfe <l.s.r@web.de> writes:\n\n> Strip \"UTF\" and an optional dash from the start of 'upper' without\n> passing a NULL pointer to skip_prefix() in the second call, as it cannot\n> handle that.\n\nDid the original meant to say \"skip UTF- from the beginning of upper\nand store it to stripped, or if that cannot be done, skip UTF from\nthe beginning of upper and store it to stripped\", but made the\nsecond one scan the stripped instead of upper by mistake?\n\nChanging it to \"skip UTF from upper and store it to stripped, and if\nthe resulting stripped begins with dash, advance stripped to skip\nthat too\" is certainly a right fix.  Fixing the second one to scan\nupper would also make the result correct, but there is no point\nscanning the same thing twice to skip the same leading \"UTF\"\nsubstring.\n\nThanks.\n\n>\n> Signed-off-by: René Scharfe <l.s.r@web.de>\n> ---\n>  convert.c | 8 ++++----\n>  1 file changed, 4 insertions(+), 4 deletions(-)\n>\n> diff --git a/convert.c b/convert.c\n> index deb6f71b2d..25ac525d5f 100644\n> --- a/convert.c\n> +++ b/convert.c\n> @@ -290,8 +290,8 @@ static int validate_encoding(const char *path, const char *enc,\n>  \t\t\tconst char *stripped = NULL;\n>  \t\t\tchar *upper = xstrdup_toupper(enc);\n>  \t\t\tupper[strlen(upper)-2] = '\\0';\n> -\t\t\tif (!skip_prefix(upper, \"UTF-\", &stripped))\n> -\t\t\t\tskip_prefix(stripped, \"UTF\", &stripped);\n> +\t\t\tif (skip_prefix(upper, \"UTF\", &stripped))\n> +\t\t\t\tskip_prefix(stripped, \"-\", &stripped);\n>  \t\t\tadvise(advise_msg, path, stripped);\n>  \t\t\tfree(upper);\n>  \t\t\tif (die_on_error)\n> @@ -310,8 +310,8 @@ static int validate_encoding(const char *path, const char *enc,\n>  \t\t\t\t\"working-tree-encoding.\");\n>  \t\t\tconst char *stripped = NULL;\n>  \t\t\tchar *upper = xstrdup_toupper(enc);\n> -\t\t\tif (!skip_prefix(upper, \"UTF-\", &stripped))\n> -\t\t\t\tskip_prefix(stripped, \"UTF\", &stripped);\n> +\t\t\tif (skip_prefix(upper, \"UTF\", &stripped))\n> +\t\t\t\tskip_prefix(stripped, \"-\", &stripped);\n>  \t\t\tadvise(advise_msg, path, stripped, stripped);\n>  \t\t\tfree(upper);\n>  \t\t\tif (die_on_error)\n> --\n> 2.23.0\n"}]}