diff --git a/source/arm9/config.c b/source/arm9/config.c index 92aa6ea..1e11dc3 100644 --- a/source/arm9/config.c +++ b/source/arm9/config.c @@ -324,9 +324,16 @@ u32 remainingLen = MAX_FILE_SIZE - curLen; u32 totalLen = strlen(textData); u32 defLen = strlen(def); - totalLen += strlen(keyName); + u32 keyLen = strlen(keyName); + + if(totalLen > remainingLen) + return NULL; + + totalLen += keyLen; totalLen += defLen; - totalLen += 2; // new line encoding + + if(curLen != 0) + totalLen += 2; // new line encoding if(totalLen > remainingLen) return NULL; @@ -337,9 +344,10 @@ filebuf[curLen++] = 0x0d; filebuf[curLen++] = 0x0a; } + sprintf(&filebuf[curLen], "%s%s%s", keyName, def, textData); - return &filebuf[curLen + defLen]; + return &filebuf[curLen + keyLen + defLen]; } static u32 writeUpdateDefinitionText(char *textData, u32 curTextLen, const char *newText) @@ -490,8 +498,6 @@ memcpy(buf, path, len); buf[len] = '\0'; - attr->textLength = len; - writeAttributeText(attr, path, key); return true; diff --git a/source/util.c b/source/util.c index 6831e09..a10741c 100644 --- a/source/util.c +++ b/source/util.c @@ -74,9 +74,6 @@ actualSize = min(dstRemaining, srcRemaining); - if(actualSize == 0) - return; - if(reverse) { u8 *src = srcBuf + srcBufOffset + actualSize - 1;