Skip to content

Commit a5107b9

Browse files
author
Jochem Berndsen
committed
fix small issue in character decoding
1 parent 7732801 commit a5107b9

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/ifcparse/IfcCharacterDecoder.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,13 @@ using namespace IfcParse;
7171
void IfcCharacterDecoder::addChar(std::stringstream& s,const UChar32& ch) {
7272
#ifdef HAVE_ICU
7373
if ( destination ) {
74-
char* extraction_buffer = new char[4];
75-
UnicodeString(ch).extract(extraction_buffer,4,destination,status);
74+
/* Note: The extraction buffer is of size 5, because in the UTF-8 encoding the
75+
maximum length in bytes is 4. We add 1 for the NUL character. In other encodings
76+
the length could be higher, but we have not taken that into account. */
77+
char extraction_buffer[5] = {};
78+
UnicodeString(ch).extract(extraction_buffer,5,destination,status);
79+
extraction_buffer[4] = '\0';
7680
s << extraction_buffer;
77-
delete extraction_buffer;
7881
} else {
7982
std::stringstream s2;
8083
s2 << "\\u" << std::hex << std::setw(4) << std::setfill('0') << (int) ch;
@@ -174,6 +177,8 @@ IfcCharacterDecoder::operator std::string() {
174177
throw IfcException("Invalid character encountered");
175178
} else {
176179
parse_state = hex = hex_count = 0;
180+
// NOTE: this is in fact wrong, this ought to be the representation of the character.
181+
// In UTF-8 this is the same, but we should not rely on that.
177182
s.put(current_char);
178183
}
179184
file->Inc();

0 commit comments

Comments
 (0)