From 67380f51cf1eae325ed0c1c3040534ac0893bc44 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Fri, 13 May 2022 17:30:17 +0200 Subject: [PATCH] fixed invalid allocations I forgot to add sizeof(int) --- src/lib/decrypter.c | 8 ++++---- src/lib/encrypter.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib/decrypter.c b/src/lib/decrypter.c index 685f8be..a6e1642 100644 --- a/src/lib/decrypter.c +++ b/src/lib/decrypter.c @@ -33,9 +33,9 @@ outputFlags decryptText(char *text, char *key, inputFlags flags) } //SET LENGTH (numberBuffer) - returningText = malloc(numberBuffer); - textKeyChain = malloc(numberBuffer * sizeof(int)); - int encryptedTextKeyChain[numberBuffer]; + returningText = malloc(sizeof(int) * numberBuffer); + textKeyChain = malloc(sizeof(int) * numberBuffer); + int encryptedTextKeyChain[sizeof(int) * numberBuffer]; textKeyChainLength = numberBuffer; //LOAD textKeyChain @@ -54,7 +54,7 @@ outputFlags decryptText(char *text, char *key, inputFlags flags) numberBuffer++; } - textBuffer = malloc(numberBuffer); + textBuffer = malloc(sizeof(int) * numberBuffer); //LOAD textBuffer for (int j = 0; j < strlen(text); j++) diff --git a/src/lib/encrypter.c b/src/lib/encrypter.c index 9a93395..7b3e32e 100644 --- a/src/lib/encrypter.c +++ b/src/lib/encrypter.c @@ -17,10 +17,10 @@ outputFlags encryptText(char *text, char *keyNew, inputFlags flags) srand(time(0)); //TRY TO MAKE RANDOM GENERATION REALLY "RANDOM" //VARIABLES - char *key = malloc(getKeyLength()); + char *key = malloc(sizeof(int) * getKeyLength()); char *returningText; char *textBuffer; - int *textKeyChain = malloc(strlen(text) * sizeof(int)); + int *textKeyChain = malloc(sizeof(int) * strlen(text)); int numberBuffer = 0; if (keyNew != NULL) @@ -75,13 +75,13 @@ outputFlags encryptText(char *text, char *keyNew, inputFlags flags) } //ALLOCATE returningText (WITH THE SEPARATORS) - returningText = malloc(numberBuffer + strlen(text) - 1); + returningText = malloc(sizeof(int) * numberBuffer + strlen(text) - 1); strcpy(returningText, ""); //LOAD returningText for (int i = 0; i < strlen(text); i++) { - textBuffer = malloc(countIntLength(textKeyChain[i])); + textBuffer = malloc(sizeof(int) * countIntLength(textKeyChain[i])); sprintf(textBuffer, "%d", textKeyChain[i]);