1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-05-25 13:54:49 -05:00

Rationalise null pointer checks in both decode_codepage functions, so

that decode_codepage(NULL) and decode_codepage("") both return the
default character set.

[originally from svn r9961]
This commit is contained in:
Simon Tatham 2013-07-22 07:12:05 +00:00
parent f9f93584c2
commit 61e555ec79
2 changed files with 43 additions and 46 deletions

View File

@ -265,7 +265,7 @@ const char *cp_enumerate(int index)
int decode_codepage(char *cp_name) int decode_codepage(char *cp_name)
{ {
if (!*cp_name) if (!cp_name || !*cp_name)
return CS_UTF8; return CS_UTF8;
return charset_from_localenc(cp_name); return charset_from_localenc(cp_name);
} }

View File

@ -1016,56 +1016,53 @@ int decode_codepage(char *cp_name)
int codepage = -1; int codepage = -1;
CPINFO cpinfo; CPINFO cpinfo;
if (!*cp_name) if (!cp_name || !*cp_name)
return CP_UTF8; /* default */ return CP_UTF8; /* default */
if (cp_name && *cp_name) for (cpi = cp_list; cpi->name; cpi++) {
for (cpi = cp_list; cpi->name; cpi++) { s = cp_name;
s = cp_name; d = cpi->name;
d = cpi->name; for (;;) {
for (;;) { while (*s && !isalnum(*s) && *s != ':')
while (*s && !isalnum(*s) && *s != ':') s++;
s++; while (*d && !isalnum(*d) && *d != ':')
while (*d && !isalnum(*d) && *d != ':') d++;
d++; if (*s == 0) {
if (*s == 0) { codepage = cpi->codepage;
codepage = cpi->codepage; if (codepage == CP_UTF8)
if (codepage == CP_UTF8) goto break_break;
goto break_break; if (codepage == -1)
if (codepage == -1) return codepage;
return codepage; if (codepage == 0) {
if (codepage == 0) { codepage = 65536 + (cpi - cp_list);
codepage = 65536 + (cpi - cp_list); goto break_break;
goto break_break; }
}
if (GetCPInfo(codepage, &cpinfo) != 0) if (GetCPInfo(codepage, &cpinfo) != 0)
goto break_break; goto break_break;
} }
if (tolower(*s++) != tolower(*d++)) if (tolower(*s++) != tolower(*d++))
break; break;
} }
}
if (cp_name && *cp_name) {
d = cp_name;
if (tolower(d[0]) == 'c' && tolower(d[1]) == 'p')
d += 2;
if (tolower(d[0]) == 'i' && tolower(d[1]) == 'b'
&& tolower(d[2]) == 'm')
d += 3;
for (s = d; *s >= '0' && *s <= '9'; s++);
if (*s == 0 && s != d)
codepage = atoi(d); /* CP999 or IBM999 */
if (codepage == CP_ACP)
codepage = GetACP();
if (codepage == CP_OEMCP)
codepage = GetOEMCP();
if (codepage > 65535)
codepage = -2;
} }
d = cp_name;
if (tolower(d[0]) == 'c' && tolower(d[1]) == 'p')
d += 2;
if (tolower(d[0]) == 'i' && tolower(d[1]) == 'b'
&& tolower(d[2]) == 'm')
d += 3;
for (s = d; *s >= '0' && *s <= '9'; s++);
if (*s == 0 && s != d)
codepage = atoi(d); /* CP999 or IBM999 */
if (codepage == CP_ACP)
codepage = GetACP();
if (codepage == CP_OEMCP)
codepage = GetOEMCP();
if (codepage > 65535)
codepage = -2;
break_break:; break_break:;
if (codepage != -1) { if (codepage != -1) {
if (codepage != CP_UTF8 && codepage < 65536) { if (codepage != CP_UTF8 && codepage < 65536) {