From 93511b79b8f756347a81cf174ed99bf900d81042 Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 22 Jul 2013 07:12:05 +0000 Subject: [PATCH] Rationalise null pointer checks in both decode_codepage functions, so that decode_codepage(NULL) and decode_codepage("") both return the default character set. git-svn-id: svn://svn.tartarus.org/sgt/putty@9961 cda61777-01e9-0310-a592-d414129be87e --- unix/uxucs.c | 2 +- windows/winucs.c | 89 +++++++++++++++++++++++++++----------------------------- 2 files changed, 44 insertions(+), 47 deletions(-) diff --git a/unix/uxucs.c b/unix/uxucs.c index 8cd300d3..5d3d5af0 100644 --- a/unix/uxucs.c +++ b/unix/uxucs.c @@ -265,7 +265,7 @@ const char *cp_enumerate(int index) int decode_codepage(char *cp_name) { - if (!*cp_name) + if (!cp_name || !*cp_name) return CS_UTF8; return charset_from_localenc(cp_name); } diff --git a/windows/winucs.c b/windows/winucs.c index cd509835..857ffb1b 100644 --- a/windows/winucs.c +++ b/windows/winucs.c @@ -1016,56 +1016,53 @@ int decode_codepage(char *cp_name) int codepage = -1; CPINFO cpinfo; - if (!*cp_name) + if (!cp_name || !*cp_name) return CP_UTF8; /* default */ - if (cp_name && *cp_name) - for (cpi = cp_list; cpi->name; cpi++) { - s = cp_name; - d = cpi->name; - for (;;) { - while (*s && !isalnum(*s) && *s != ':') - s++; - while (*d && !isalnum(*d) && *d != ':') - d++; - if (*s == 0) { - codepage = cpi->codepage; - if (codepage == CP_UTF8) - goto break_break; - if (codepage == -1) - return codepage; - if (codepage == 0) { - codepage = 65536 + (cpi - cp_list); - goto break_break; - } - - if (GetCPInfo(codepage, &cpinfo) != 0) - goto break_break; - } - if (tolower(*s++) != tolower(*d++)) - 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; + for (cpi = cp_list; cpi->name; cpi++) { + s = cp_name; + d = cpi->name; + for (;;) { + while (*s && !isalnum(*s) && *s != ':') + s++; + while (*d && !isalnum(*d) && *d != ':') + d++; + if (*s == 0) { + codepage = cpi->codepage; + if (codepage == CP_UTF8) + goto break_break; + if (codepage == -1) + return codepage; + if (codepage == 0) { + codepage = 65536 + (cpi - cp_list); + goto break_break; + } + + if (GetCPInfo(codepage, &cpinfo) != 0) + goto break_break; + } + if (tolower(*s++) != tolower(*d++)) + break; + } } + 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:; if (codepage != -1) { if (codepage != CP_UTF8 && codepage < 65536) { -- 2.11.0