replaced malloc in loop with realloc

when I was coding first version of WHY2 I didn't know there's something like it lulw
This commit is contained in:
Václav Šmejkal 2022-05-22 15:26:17 +02:00
parent a898f8a824
commit 9a2663c7a4

View File

@ -84,7 +84,15 @@ outputFlags encryptText(char *text, char *keyNew, inputFlags flags)
//LOAD returningText
for (int i = 0; i < strlen(text); i++)
{
textBuffer = malloc(sizeof(int) * countIntLength(textKeyChain[i]));
numberBuffer = sizeof(int) * countIntLength(textKeyChain[i]);
if (i != 0)
{
textBuffer = realloc(textBuffer, numberBuffer);
} else
{
textBuffer = malloc(numberBuffer);
}
sprintf(textBuffer, "%d", textKeyChain[i]);
@ -94,8 +102,6 @@ outputFlags encryptText(char *text, char *keyNew, inputFlags flags)
{
strcat(returningText, ENCRYPTION_SEPARATOR_STRING);
}
free(textBuffer);
}
//LOAD output
@ -108,6 +114,7 @@ outputFlags encryptText(char *text, char *keyNew, inputFlags flags)
//DEALLOCATION
fclose(fileBuffer);
free(textKeyChain);
free(textBuffer);
return output;
}