Skip to content

Commit 9a27f96

Browse files
committed
precompose-utf8: do not call checks for non-ascii "utf8"
As suggested by Linus, this function is not checking UTF-8-ness of the string; it only is seeing if it is pure US-ASCII. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5f8580a commit 9a27f96

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

compat/precompose_utf8.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ typedef char *iconv_ibp;
1313
static const char *repo_encoding = "UTF-8";
1414
static const char *path_encoding = "UTF-8-MAC";
1515

16-
static size_t has_utf8(const char *s, size_t maxlen, size_t *strlen_c)
16+
static size_t has_non_ascii(const char *s, size_t maxlen, size_t *strlen_c)
1717
{
18-
const uint8_t *utf8p = (const uint8_t *)s;
18+
const uint8_t *ptr = (const uint8_t *)s;
1919
size_t strlen_chars = 0;
2020
size_t ret = 0;
2121

22-
if (!utf8p || !*utf8p)
22+
if (!ptr || !*ptr)
2323
return 0;
2424

25-
while (*utf8p && maxlen) {
26-
if (*utf8p & 0x80)
25+
while (*ptr && maxlen) {
26+
if (*ptr & 0x80)
2727
ret++;
2828
strlen_chars++;
29-
utf8p++;
29+
ptr++;
3030
maxlen--;
3131
}
3232
if (strlen_c)
@@ -77,7 +77,7 @@ void precompose_argv(int argc, const char **argv)
7777
while (i < argc) {
7878
size_t namelen;
7979
oldarg = argv[i];
80-
if (has_utf8(oldarg, (size_t)-1, &namelen)) {
80+
if (has_non_ascii(oldarg, (size_t)-1, &namelen)) {
8181
newarg = reencode_string_iconv(oldarg, namelen, ic_precompose);
8282
if (newarg)
8383
argv[i] = newarg;
@@ -130,7 +130,7 @@ struct dirent_prec_psx *precompose_utf8_readdir(PREC_DIR *prec_dir)
130130
prec_dir->dirent_nfc->d_ino = res->d_ino;
131131
prec_dir->dirent_nfc->d_type = res->d_type;
132132

133-
if ((precomposed_unicode == 1) && has_utf8(res->d_name, (size_t)-1, NULL)) {
133+
if ((precomposed_unicode == 1) && has_non_ascii(res->d_name, (size_t)-1, NULL)) {
134134
if (prec_dir->ic_precompose == (iconv_t)-1) {
135135
die("iconv_open(%s,%s) failed, but needed:\n"
136136
" precomposed unicode is not supported.\n"

0 commit comments

Comments
 (0)