From a2bda4b95508b2fac9dce859a39c836c156fc23c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Fri, 28 Jun 2019 11:18:24 +0200 Subject: [PATCH] [ion/utf8_helper] Fix RemoveCodePoint The index to update was not updated properly --- ion/include/ion/unicode/utf8_helper.h | 2 +- ion/src/shared/unicode/utf8_helper.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ion/include/ion/unicode/utf8_helper.h b/ion/include/ion/unicode/utf8_helper.h index a0abfcc04..3a6eb9a00 100644 --- a/ion/include/ion/unicode/utf8_helper.h +++ b/ion/include/ion/unicode/utf8_helper.h @@ -24,7 +24,7 @@ void CopyAndRemoveCodePoint(char * dst, size_t dstSize, const char * src, CodePo /* Remove all code points c. and update an index that should be lower if code * points where removed before it. Ensure null-termination of dst. */ -void RemoveCodePoint(char * buffer, CodePoint c, const char * * indexToDUpdate = nullptr, const char * stoppingPosition = nullptr); +void RemoveCodePoint(char * buffer, CodePoint c, const char * * indexToUpdate = nullptr, const char * stoppingPosition = nullptr); /* Copy src into dst until end of dst or code point c, with null termination. Return the length of the copy */ size_t CopyUntilCodePoint(char * dst, size_t dstSize, const char * src, CodePoint c); diff --git a/ion/src/shared/unicode/utf8_helper.cpp b/ion/src/shared/unicode/utf8_helper.cpp index 5a9e66c16..9f9537bb1 100644 --- a/ion/src/shared/unicode/utf8_helper.cpp +++ b/ion/src/shared/unicode/utf8_helper.cpp @@ -119,6 +119,7 @@ void RemoveCodePoint(char * buffer, CodePoint c, const char * * pointerToUpdate, UTF8Decoder decoder(buffer); const char * currentPointer = buffer; CodePoint codePoint = decoder.nextCodePoint(); + const char * initialPointerToUpdate = *pointerToUpdate; const char * nextPointer = decoder.stringPosition(); size_t bufferIndex = 0; size_t codePointCharSize = UTF8Decoder::CharSizeOfCodePoint(c); @@ -128,7 +129,7 @@ void RemoveCodePoint(char * buffer, CodePoint c, const char * * pointerToUpdate, int copySize = nextPointer - currentPointer; memmove(buffer + bufferIndex, currentPointer, copySize); bufferIndex+= copySize; - } else if (pointerToUpdate != nullptr && currentPointer < *pointerToUpdate) { + } else if (pointerToUpdate != nullptr && currentPointer < initialPointerToUpdate) { assert(*pointerToUpdate - buffer >= codePointCharSize); *pointerToUpdate = *pointerToUpdate - codePointCharSize; }