From f8f53b43054fdae8df0d95e36ae00620d65361fb Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Wed, 1 Feb 2023 15:11:27 +0100 Subject: [PATCH] implemented why2_strdup hehe --- src/core/lib/decrypter.c | 4 ++-- src/core/lib/encrypter.c | 2 +- src/core/lib/test/main.c | 8 ++++---- src/logger/lib/logger.c | 6 +++--- src/logger/lib/utils.c | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/core/lib/decrypter.c b/src/core/lib/decrypter.c index 11c5ea0..5d02234 100644 --- a/src/core/lib/decrypter.c +++ b/src/core/lib/decrypter.c @@ -65,9 +65,9 @@ why2_output_flags why2_decrypt_text(char *text, char *keyNew) char *textBuffer = why2_malloc(1); int textKeyChainLength; int *textKeyChain; - char *key = strdup(keyNew); //COPY keyNew TO key + char *key = why2_strdup(keyNew); //COPY keyNew TO key int *encryptedTextKeyChain; - char *usedText = strdup(text); //COPY text TO usedText + char *usedText = why2_strdup(text); //COPY text TO usedText //GET LENGTH OF returningText AND textKeyChain for (int i = 0; i < (int) strlen(usedText); i++) diff --git a/src/core/lib/encrypter.c b/src/core/lib/encrypter.c index 1810d23..536e405 100644 --- a/src/core/lib/encrypter.c +++ b/src/core/lib/encrypter.c @@ -63,7 +63,7 @@ why2_output_flags why2_encrypt_text(char *text, char *keyNew) return why2_no_output(checkExitCode); } - key = strdup(keyNew); + key = why2_strdup(keyNew); //REDEFINE keyLength why2_set_key_length(strlen(key)); diff --git a/src/core/lib/test/main.c b/src/core/lib/test/main.c index d82d908..0e1fe34 100644 --- a/src/core/lib/test/main.c +++ b/src/core/lib/test/main.c @@ -64,8 +64,8 @@ int main(void) //ENCRYPT why2_output_flags encrypted = why2_encrypt_text(WHY2_TEST_TEXT, NULL); - textBuffer = strdup(encrypted.outputText); //GET ENCRYPTED TEXT - keyBuffer = strdup(encrypted.usedKey); //GET KEY + textBuffer = why2_strdup(encrypted.outputText); //GET ENCRYPTED TEXT + keyBuffer = why2_strdup(encrypted.usedKey); //GET KEY timeBuffer = encrypted.elapsedTime; //GET TIME 1 //DEALLOCATE BUFFER @@ -79,11 +79,11 @@ int main(void) //COMPARE DIFFERENCE if (strcmp(encrypted.outputText, WHY2_TEST_TEXT) == 0 && encrypted.exitCode == 0) //WHY2_SUCCESS { - statusBuffer = strdup("successful"); + statusBuffer = why2_strdup("successful"); } else //FAILURE { - statusBuffer = strdup("failed"); + statusBuffer = why2_strdup("failed"); outputBuffer = why2_realloc(outputBuffer, strlen(encrypted.outputText) + 6); sprintf(outputBuffer, "\t\t\"%s\"\n", encrypted.outputText); diff --git a/src/logger/lib/logger.c b/src/logger/lib/logger.c index 2d77e21..fc7e732 100644 --- a/src/logger/lib/logger.c +++ b/src/logger/lib/logger.c @@ -79,7 +79,7 @@ why2_log_file why2_init_logger(char *directoryPath) //CREATE SYMLINK sprintf(latestBuffer, WHY2_LOG_LATEST_FORMATTING, WHY2_WRITE_DIR, WHY2_LOG_LATEST); //GENERATE LATEST.log PATH - latestFilePath = strdup(filePath); + latestFilePath = why2_strdup(filePath); if (access(latestBuffer, R_OK) == 0) { unlink(latestBuffer); } //REMOVE SYMLINK IF IT ALREADY EXISTS (void) (symlink(latestFilePath + (strlen(WHY2_WRITE_DIR) + 1), latestBuffer) + 1); //TODO: Try to create some function for processing exit value //CREATE @@ -108,7 +108,7 @@ void why2_write_log(int loggerFile, char *logMessage) } //COPY logMessage without '\n' - char *logMessageUsed = strdup(logMessage); + char *logMessageUsed = why2_strdup(logMessage); for (int i = 0; i < (int) strlen(logMessageUsed); i++) { if (logMessageUsed[i] == '\n') logMessageUsed[i] = '\0'; @@ -128,7 +128,7 @@ void why2_write_log(int loggerFile, char *logMessage) { why2_output_flags encrypted = why2_encrypt_text(logMessageUsed, flags.key); //ENCRYPT - message = strdup(encrypted.outputText); //COPY + message = why2_strdup(encrypted.outputText); //COPY //DEALLOCATION why2_deallocate_output(encrypted); diff --git a/src/logger/lib/utils.c b/src/logger/lib/utils.c index e449305..cf0cf9c 100644 --- a/src/logger/lib/utils.c +++ b/src/logger/lib/utils.c @@ -101,7 +101,7 @@ why2_decrypted_output why2_decrypt_logger(why2_log_file logger) { outputBuffer = why2_decrypt_text(content[i], why2_get_log_flags().key); //DECRYPT - contentDecrypted[i] = strdup(outputBuffer.outputText); //COPY + contentDecrypted[i] = why2_strdup(outputBuffer.outputText); //COPY why2_deallocate_output(outputBuffer); //DEALLOCATE outputBuffer }