Skip to content

Commit

Permalink
Fixed some minor errors:
Browse files Browse the repository at this point in the history
1) Avoid possible problems with table size calculation
2) Assume CP437 if charset detection fails
  • Loading branch information
unxed committed May 22, 2024
1 parent dbadea0 commit 1ca13d8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion CPP/7zip/Archive/Zip/ZipItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,12 @@ void CItem::GetUnicodeString(UString &res, const AString &s, bool isComment, boo
if (isOem || isAnsi) {

const char *legacyCp = nullptr;
int tableLen = sizeof(isOem ? lcToOemTable : lcToAnsiTable) / sizeof(char *);
int tableLen;
if (isOem) {
tableLen = sizeof(lcToOemTable) / sizeof(lcToOemTable[0]);
} else {
tableLen = sizeof(lcToAnsiTable) / sizeof(lcToAnsiTable[0]);
}
int lcLen = 0, i;

// Detect required code page name from current locale
Expand All @@ -465,6 +470,11 @@ void CItem::GetUnicodeString(UString &res, const AString &s, bool isComment, boo
}
}

// not found; use 437 by default
if (!legacyCp) {
legacyCp = "CP437";
}

if (legacyCp) {
iconv_t cd;
if ((cd = iconv_open("UTF-8", legacyCp)) != (iconv_t)-1) {
Expand Down

0 comments on commit 1ca13d8

Please sign in to comment.