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:
parent
a898f8a824
commit
9a2663c7a4
@ -84,7 +84,15 @@ outputFlags encryptText(char *text, char *keyNew, inputFlags flags)
|
|||||||
//LOAD returningText
|
//LOAD returningText
|
||||||
for (int i = 0; i < strlen(text); i++)
|
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]);
|
sprintf(textBuffer, "%d", textKeyChain[i]);
|
||||||
|
|
||||||
@ -94,8 +102,6 @@ outputFlags encryptText(char *text, char *keyNew, inputFlags flags)
|
|||||||
{
|
{
|
||||||
strcat(returningText, ENCRYPTION_SEPARATOR_STRING);
|
strcat(returningText, ENCRYPTION_SEPARATOR_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(textBuffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//LOAD output
|
//LOAD output
|
||||||
@ -108,6 +114,7 @@ outputFlags encryptText(char *text, char *keyNew, inputFlags flags)
|
|||||||
//DEALLOCATION
|
//DEALLOCATION
|
||||||
fclose(fileBuffer);
|
fclose(fileBuffer);
|
||||||
free(textKeyChain);
|
free(textKeyChain);
|
||||||
|
free(textBuffer);
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user