From e94c273bd95b862bf17129e7572b3e6e59b89b28 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Thu, 26 May 2022 19:35:22 +0200 Subject: [PATCH] probably fixed deallocateOutput segfault I thought the key returned as outputFlags (decrypter) was pointer to completely new address, but it often tried to deallocate unallocated key --- include/decrypter.h | 2 +- src/lib/decrypter.c | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/decrypter.h b/include/decrypter.h index 797b8d9..81d1a0b 100644 --- a/include/decrypter.h +++ b/include/decrypter.h @@ -3,6 +3,6 @@ #include -outputFlags decryptText(char *text, char *key, inputFlags flags); //TEXT from WILL BE DECRYPTED WITH KEY AND RETURNED +outputFlags decryptText(char *text, char *keyNew, inputFlags flags); //TEXT from WILL BE DECRYPTED WITH KEY AND RETURNED #endif \ No newline at end of file diff --git a/src/lib/decrypter.c b/src/lib/decrypter.c index 3f8368e..b206590 100644 --- a/src/lib/decrypter.c +++ b/src/lib/decrypter.c @@ -7,13 +7,13 @@ #include #include -outputFlags decryptText(char *text, char *key, inputFlags flags) +outputFlags decryptText(char *text, char *keyNew, inputFlags flags) { //CHECK FOR INVALID key - checkKey(key, flags); + checkKey(keyNew, flags); //REDEFINE keyLength - setKeyLength(strlen(key)); + setKeyLength(strlen(keyNew)); //VARIABLES char *returningText; @@ -21,6 +21,10 @@ outputFlags decryptText(char *text, char *key, inputFlags flags) char *textBuffer; int textKeyChainLength; int *textKeyChain; + char *key = malloc(strlen(keyNew)); + + //COPY keyNew TO key + strcpy(key, keyNew); //GET LENGTH OF returningText AND textKeyChain for (int i = 0; i < strlen(text); i++)