aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2018-04-15 20:53:29 +0300
committerZyX <kp-pav@yandex.ru>2018-04-15 20:53:29 +0300
commita2f91884187de00d5b96065587d3d927409af5bc (patch)
treebdb8990ff4714a9dd09f2f955ba2656d072c541e
parent24ee2613174250f9d32492c435c42daef3a44b21 (diff)
downloadrneovim-a2f91884187de00d5b96065587d3d927409af5bc.tar.gz
rneovim-a2f91884187de00d5b96065587d3d927409af5bc.tar.bz2
rneovim-a2f91884187de00d5b96065587d3d927409af5bc.zip
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.
-rw-r--r--src/nvim/mbyte.c50
1 files changed, 26 insertions, 24 deletions
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index 446063e33b..a52ab9f5d3 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -1979,37 +1979,39 @@ char_u * enc_locale(void)
return NULL;
}
- /* The most generic locale format is:
- * language[_territory][.codeset][@modifier][+special][,[sponsor][_revision]]
- * If there is a '.' remove the part before it.
- * if there is something after the codeset, remove it.
- * Make the name lowercase and replace '_' with '-'.
- * Exception: "ja_JP.EUC" == "euc-jp", "zh_CN.EUC" = "euc-cn",
- * "ko_KR.EUC" == "euc-kr"
- */
+ // The most generic locale format is:
+ // language[_territory][.codeset][@modifier][+special][,[sponsor][_revision]]
+ // If there is a '.' remove the part before it.
+ // if there is something after the codeset, remove it.
+ // Make the name lowercase and replace '_' with '-'.
+ // Exception: "ja_JP.EUC" == "euc-jp", "zh_CN.EUC" = "euc-cn",
+ // "ko_KR.EUC" == "euc-kr"
const char *p = (char *)vim_strchr((char_u *)s, '.');
if (p != NULL) {
if (p > s + 2 && !STRNICMP(p + 1, "EUC", 3)
&& !isalnum((int)p[4]) && p[4] != '-' && p[-3] == '_') {
- /* copy "XY.EUC" to "euc-XY" to buf[10] */
- strcpy(buf + 10, "euc-");
- buf[14] = p[-2];
- buf[15] = p[-1];
- buf[16] = 0;
- 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]);
+ // Copy "XY.EUC" to "euc-XY" to buf[10].
+ memmove(buf, "euc-", 4);
+ buf[4] = (ASCII_ISALNUM(p[-2]) ? TOLOWER_ASC(p[-2]) : 0);
+ buf[5] = (ASCII_ISALNUM(p[-1]) ? TOLOWER_ASC(p[-1]) : 0);
+ buf[6] = NUL;
} 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);
}