X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=ED2KLink.cpp;h=74a38c9aadf2d321d942270cdcba003b741bd1e1;hb=a0eb955ae6aa166e2c54bcbdd2521d75264fd3ad;hp=47f3af8f0b8849a96728cf16e75bca1f592a16a3;hpb=3cf3d0fbb0576ab0eaa3f9f0f0ca19d15192d0d0;p=ecparse.git diff --git a/ED2KLink.cpp b/ED2KLink.cpp index 47f3af8..74a38c9 100644 --- a/ED2KLink.cpp +++ b/ED2KLink.cpp @@ -6,7 +6,6 @@ #include #include #include "ED2KLink.h" -#include "GrowingBuffer.h" #include "GlobalSettings.h" static int getDigits(size_t number) { @@ -19,7 +18,7 @@ static int getDigits(size_t number) { } ED2KLink::ED2KLink(const char* filename, const size_t size, const void* hash) { - this->filename = (char*) malloc(strlen(filename)); + this->filename = (char*) malloc(strlen(filename) + 1); this->hash = malloc(16); strcpy(this->filename, filename); @@ -55,7 +54,7 @@ ED2KLink* ED2KLink::parseED2KLink(const char* buffer) { int hashIndex; unsigned char hash[16]; char* pipeIndex; - GrowingBuffer growingBuffer; + int stringLength; GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] trying to parse “%s”...\n", __FILE__, __LINE__, buffer); @@ -69,11 +68,10 @@ ED2KLink* ED2KLink::parseED2KLink(const char* buffer) { GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] expected pipe character (‘|’) but found none.\n", __FILE__, __LINE__); return NULL; } - growingBuffer.write(tempBuffer, (char*) pipeIndex - tempBuffer); - filename = (char*) malloc(growingBuffer.getLimit() + 1); - growingBuffer.read(filename, growingBuffer.getLimit()); - sizeString[growingBuffer.getLimit()] = '\0'; - growingBuffer.clear(); + stringLength = (char*) pipeIndex - tempBuffer; + filename = (char*) malloc(stringLength + 1); + memcpy(filename, tempBuffer, stringLength); + sizeString[stringLength] = '\0'; tempBuffer = pipeIndex + 1; GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] parsed filename: “%s”.\n", __FILE__, __LINE__, filename); @@ -83,11 +81,10 @@ ED2KLink* ED2KLink::parseED2KLink(const char* buffer) { GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] expected pipe character (‘|’) but found none.\n", __FILE__, __LINE__); return NULL; } - growingBuffer.write(tempBuffer, (char*) pipeIndex - tempBuffer); - sizeString = (char*) malloc(growingBuffer.getLimit() + 1); - growingBuffer.read(sizeString, growingBuffer.getLimit()); - sizeString[growingBuffer.getLimit()] = '\0'; - growingBuffer.clear(); + stringLength = (char*) pipeIndex - tempBuffer; + sizeString = (char*) malloc(stringLength + 1); + memcpy(sizeString, tempBuffer, stringLength); + sizeString[stringLength] = '\0'; tempBuffer = pipeIndex + 1; size = atol(sizeString);