diff --git a/includes/RhythmGameUtilities/ParsersInternal.hpp b/includes/RhythmGameUtilities/ParsersInternal.hpp index 91a0075..2122a91 100644 --- a/includes/RhythmGameUtilities/ParsersInternal.hpp +++ b/includes/RhythmGameUtilities/ParsersInternal.hpp @@ -27,9 +27,11 @@ extern "C" for (auto i = 0; i < internalSections.size(); i += 1) { - sections[i].name = - (char *)malloc(strlen(internalSections[i].name.c_str()) + 1); - strcpy(sections[i].name, internalSections[i].name.c_str()); + auto nameLength = internalSections[i].name.size() + 1; + sections[i].name = (char *)malloc(nameLength); + strncpy(sections[i].name, internalSections[i].name.c_str(), + nameLength - 1); + sections[i].name[nameLength - 1] = '\0'; sections[i].lines = (KeyValuePairInternal *)malloc( internalSections[i].lines.size() * @@ -39,18 +41,23 @@ extern "C" for (auto j = 0; j < internalSections[i].lines.size(); j += 1) { - sections[i].lines[j].key = (char *)malloc( - strlen(internalSections[i].lines[j].first.c_str()) + 1); - strcpy(sections[i].lines[j].key, - internalSections[i].lines[j].first.c_str()); + auto keyLength = internalSections[i].lines[j].first.size() + 1; + sections[i].lines[j].key = (char *)malloc(keyLength); + strncpy(sections[i].lines[j].key, + internalSections[i].lines[j].first.c_str(), + keyLength - 1); + sections[i].lines[j].key[keyLength - 1] = '\0'; auto values = internalSections[i].lines[j].second; for (auto k = 0; k < values.size(); k += 1) { + auto valueLength = values[k].size() + 1; sections[i].lines[j].values[k] = - (char *)malloc(strlen(values[k].c_str()) + 1); - strcpy(sections[i].lines[j].values[k], values[k].c_str()); + (char *)malloc(valueLength); + strncpy(sections[i].lines[j].values[k], values[k].c_str(), + values[k].size()); + sections[i].lines[j].values[k][valueLength - 1] = '\0'; } sections[i].lines[j].valueCount = values.size();