From: Steven R. Loomis Date: Wed, 15 Mar 2017 23:48:54 +0000 (+0000) Subject: ICU-12766 fix buffer size X-Git-Tag: release-59-rc~99^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=14f45141ba05d5e67ee1a19ed9bdbddef919a23f;p=icu ICU-12766 fix buffer size X-SVN-Rev: 39831 --- diff --git a/icu4c/source/tools/escapesrc/escapesrc.cpp b/icu4c/source/tools/escapesrc/escapesrc.cpp index b249587f9b7..68845d51a6d 100644 --- a/icu4c/source/tools/escapesrc/escapesrc.cpp +++ b/icu4c/source/tools/escapesrc/escapesrc.cpp @@ -107,7 +107,7 @@ inline bool isCommentOrEmpty(const char* line, size_t len) { void appendByte(std::string &outstr, uint8_t byte) { - char tmp2[4]; + char tmp2[5]; sprintf(tmp2, "\\x%02X", 0xFF & (int)(byte)); outstr += tmp2; } @@ -124,8 +124,9 @@ bool appendUtf8(std::string &outstr, tmp[i] = linestr[++pos]; } tmp[chars] = 0; - UChar32 ch; - sscanf(tmp, "%X", &ch); + unsigned int c; + sscanf(tmp, "%X", &c); + UChar32 ch = c & 0x1FFFFF; // now to append \\x%% etc uint8_t bytesNeeded = U8_LENGTH(ch); @@ -251,9 +252,9 @@ bool fixAt(std::string &linestr, size_t pos) { size_t seqLen = (i-pos); - //printf("U+%04X pos %d [len %d]\n", c, pos, seqLen); + //printf("U+%04X pos %d [len %d]\n", c, pos, seqLen);fflush(stdout); - char newSeq[] = "\\U0000FFFD"; + char newSeq[20]; if( c <= 0xFFFF) { sprintf(newSeq, "\\u%04X", c); } else {