X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=ED2KLink.cpp;h=74a38c9aadf2d321d942270cdcba003b741bd1e1;hb=670b52477447d711f0cf0d40be66838a87666717;hp=e1ec2ffba7070b5554dcb7cde130fe5695aa545b;hpb=dc3a8cc1faaeb0b9fd1c65d88b04000ac57519eb;p=ecparse.git diff --git a/ED2KLink.cpp b/ED2KLink.cpp index e1ec2ff..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,10 +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()); - 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); @@ -82,10 +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()); - growingBuffer.clear(); + stringLength = (char*) pipeIndex - tempBuffer; + sizeString = (char*) malloc(stringLength + 1); + memcpy(sizeString, tempBuffer, stringLength); + sizeString[stringLength] = '\0'; tempBuffer = pipeIndex + 1; size = atol(sizeString); @@ -96,7 +95,10 @@ ED2KLink* ED2KLink::parseED2KLink(const char* buffer) { char byteBuffer[3]; byteBuffer[2] = '\0'; memcpy(byteBuffer, tempBuffer + hashIndex * 2, 2); - sscanf(byteBuffer, "%hhX", &hash[hashIndex]); + if (sscanf(byteBuffer, "%hhX", &hash[hashIndex]) != 1) { + GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] could not parse ‘%c%c’ into a byte.\n", __FILE__, __LINE__, *(byteBuffer), *(byteBuffer + 1)); + return NULL; + } GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] parsed ‘%c%c’ as %02x.\n", __FILE__, __LINE__, *(byteBuffer), *(byteBuffer + 1), hash[hashIndex]); }