replaced repeating malloc with realloc

tf I tried to fix this much earlier but it was throwing segfaults... I should start taking those pills
This commit is contained in:
Václav Šmejkal 2022-07-15 19:32:57 +02:00
parent 090d82842c
commit dfbf65cc0f
No known key found for this signature in database
GPG Key ID: FD749A97DF2D5E19

View File

@ -79,7 +79,13 @@ outputFlags decryptText(char *text, char *keyNew)
numberBuffer++; numberBuffer++;
} }
if (i != 0)
{
textBuffer = realloc(textBuffer, numberBuffer + 1);
} else
{
textBuffer = malloc(numberBuffer + 1); textBuffer = malloc(numberBuffer + 1);
}
//LOAD textBuffer //LOAD textBuffer
for (int j = 0; j < (int) strlen(text); j++) for (int j = 0; j < (int) strlen(text); j++)
@ -92,7 +98,6 @@ outputFlags decryptText(char *text, char *keyNew)
encryptedTextKeyChain[i] = atoi(textBuffer); encryptedTextKeyChain[i] = atoi(textBuffer);
text += numberBuffer + 1; text += numberBuffer + 1;
free(textBuffer);
} }
//DECRYPT TEXT //DECRYPT TEXT
@ -130,6 +135,7 @@ outputFlags decryptText(char *text, char *keyNew)
//DEALLOCATION //DEALLOCATION
free(textKeyChain); free(textKeyChain);
free(encryptedTextKeyChain); free(encryptedTextKeyChain);
free(textBuffer);
return output; return output;
} }