Skip to content

Commit

Permalink
Reset utf8 pointer to point at original string before using
Browse files Browse the repository at this point in the history
When an invalid utf8 sequence is found the original string
is parsed again in order to figure out where in the string
the problem occurs so that it will be possible to print
out the bytes surrounding the error in the exception msg.
The problem is that when trying to print out the bytes
around the parse error the 'utf8' pointer is used. This
pointer no longer points to the start of the erroneous
string since it has just been used in a loop where each
iteration increments it. Fixed by restoring it so that it
points to the start of the string once again.
This fixes M#1208
  • Loading branch information
Jan-Olof Hendig committed Oct 28, 2019
1 parent 0b531f9 commit da19661
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/strings/utf8.c
Expand Up @@ -237,6 +237,7 @@ MVMString * MVM_string_utf8_decode(MVMThreadContext *tc, const MVMObject *result
break;
case UTF8_REJECT: {
size_t error_pos = orig_bytes - bytes;
utf8 = orig_utf8;
MVM_free(buffer);
if (error_pos >= 3) {
unsigned char a = utf8[error_pos - 2], b = utf8[error_pos - 1], c = utf8[error_pos];
Expand Down

0 comments on commit da19661

Please sign in to comment.