X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=GrowingBuffer.cpp;h=2841741682db3ed101d7b3207ecd0421e4aa145e;hb=5055ee4c17b480e213b3afb38184530da566bb60;hp=a260a3dd1638cc21c740acc1a87a202e58a2358b;hpb=46f6c3d3ed2e03261fa726806dde9dcc605c0140;p=ecparse.git diff --git a/GrowingBuffer.cpp b/GrowingBuffer.cpp index a260a3d..2841741 100644 --- a/GrowingBuffer.cpp +++ b/GrowingBuffer.cpp @@ -58,7 +58,7 @@ void GrowingBuffer::write(const void* buffer, size_t length) { } while (length > (newSize - limit)); GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] resizing buffer from %d to %d bytes to fit in %d bytes.\n", __FILE__, __LINE__, size, newSize, length); void* newData = malloc(newSize); - memcpy(newData, data, position); + memcpy(newData, data, limit); free(data); data = newData; } @@ -98,3 +98,13 @@ void GrowingBuffer::resize(double factor) { } } +size_t GrowingBuffer::indexOf(char c, size_t start) { + void* foundIndex; + + foundIndex = memchr((ptrdiff_t*) data + position + start, c, (limit - start)); + if (foundIndex) { + return (ptrdiff_t) foundIndex - ((ptrdiff_t) data + position); + } + return -1; +} +