mirror of
https://github.com/neovim/neovim.git
synced 2025-09-27 21:48:35 +00:00
mbyte: Fix PVS/V557: do not do useless job
I do not see how array overrun is actually possible, but still EUC encodings may do fine without a cycle.
This commit is contained in:
@@ -1979,37 +1979,39 @@ char_u * enc_locale(void)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The most generic locale format is:
|
// The most generic locale format is:
|
||||||
* language[_territory][.codeset][@modifier][+special][,[sponsor][_revision]]
|
// language[_territory][.codeset][@modifier][+special][,[sponsor][_revision]]
|
||||||
* If there is a '.' remove the part before it.
|
// If there is a '.' remove the part before it.
|
||||||
* if there is something after the codeset, remove it.
|
// if there is something after the codeset, remove it.
|
||||||
* Make the name lowercase and replace '_' with '-'.
|
// Make the name lowercase and replace '_' with '-'.
|
||||||
* Exception: "ja_JP.EUC" == "euc-jp", "zh_CN.EUC" = "euc-cn",
|
// Exception: "ja_JP.EUC" == "euc-jp", "zh_CN.EUC" = "euc-cn",
|
||||||
* "ko_KR.EUC" == "euc-kr"
|
// "ko_KR.EUC" == "euc-kr"
|
||||||
*/
|
|
||||||
const char *p = (char *)vim_strchr((char_u *)s, '.');
|
const char *p = (char *)vim_strchr((char_u *)s, '.');
|
||||||
if (p != NULL) {
|
if (p != NULL) {
|
||||||
if (p > s + 2 && !STRNICMP(p + 1, "EUC", 3)
|
if (p > s + 2 && !STRNICMP(p + 1, "EUC", 3)
|
||||||
&& !isalnum((int)p[4]) && p[4] != '-' && p[-3] == '_') {
|
&& !isalnum((int)p[4]) && p[4] != '-' && p[-3] == '_') {
|
||||||
/* copy "XY.EUC" to "euc-XY" to buf[10] */
|
// Copy "XY.EUC" to "euc-XY" to buf[10].
|
||||||
strcpy(buf + 10, "euc-");
|
memmove(buf, "euc-", 4);
|
||||||
buf[14] = p[-2];
|
buf[4] = (ASCII_ISALNUM(p[-2]) ? TOLOWER_ASC(p[-2]) : 0);
|
||||||
buf[15] = p[-1];
|
buf[5] = (ASCII_ISALNUM(p[-1]) ? TOLOWER_ASC(p[-1]) : 0);
|
||||||
buf[16] = 0;
|
buf[6] = NUL;
|
||||||
s = buf + 10;
|
|
||||||
} else
|
|
||||||
s = p + 1;
|
|
||||||
}
|
|
||||||
for (i = 0; i < (int)sizeof(buf) - 1 && s[i] != NUL; i++) {
|
|
||||||
if (s[i] == '_' || s[i] == '-') {
|
|
||||||
buf[i] = '-';
|
|
||||||
} else if (isalnum((int)s[i])) {
|
|
||||||
buf[i] = TOLOWER_ASC(s[i]);
|
|
||||||
} else {
|
} else {
|
||||||
break;
|
s = p + 1;
|
||||||
|
goto enc_locale_copy_enc;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
enc_locale_copy_enc:
|
||||||
|
for (i = 0; i < (int)sizeof(buf) - 1 && s[i] != NUL; i++) {
|
||||||
|
if (s[i] == '_' || s[i] == '-') {
|
||||||
|
buf[i] = '-';
|
||||||
|
} else if (ASCII_ISALNUM((uint8_t)s[i])) {
|
||||||
|
buf[i] = TOLOWER_ASC(s[i]);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buf[i] = NUL;
|
||||||
}
|
}
|
||||||
buf[i] = NUL;
|
|
||||||
|
|
||||||
return enc_canonize((char_u *)buf);
|
return enc_canonize((char_u *)buf);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user