fix an endless loop in unicode_utf8_to_cp437 for characters not in the table.

This commit is contained in:
Enno Rehling 2016-10-02 12:46:07 +02:00 committed by Enno Rehling
parent f6b3027d63
commit 331015a511
2 changed files with 19 additions and 4 deletions

View File

@ -506,10 +506,14 @@ size_t * length)
*cp_character = (char)xref[m].cp437; *cp_character = (char)xref[m].cp437;
break; break;
} }
else if (xref[m].ucs4 < ucs4_character) else if (xref[m].ucs4 < ucs4_character) {
l = m; if (l == m) l = r;
else else l = m;
r = m; }
else {
if (r == m) r = l;
else r = m;
}
} }
if (l == r) { if (l == r) {
*cp_character = '?'; *cp_character = '?';

View File

@ -16,9 +16,20 @@ static void test_unicode_tolower(CuTest * tc)
CuAssertStrEquals(tc, "helloX", buffer); CuAssertStrEquals(tc, "helloX", buffer);
} }
static void test_unicode_utf8_to_cp437(CuTest *tc)
{
const char utf8_str[4] = { 0xc3, 0x98, 'l', 0 }; // &Oslash;l
char ch;
size_t sz;
CuAssertIntEquals(tc, 0, unicode_utf8_to_cp437(&ch, utf8_str, &sz));
CuAssertIntEquals(tc, 2, sz);
CuAssertIntEquals(tc, '?', ch);
}
CuSuite *get_unicode_suite(void) CuSuite *get_unicode_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_unicode_tolower); SUITE_ADD_TEST(suite, test_unicode_tolower);
SUITE_ADD_TEST(suite, test_unicode_utf8_to_cp437);
return suite; return suite;
} }