removed pointless strlen from for loops

This commit is contained in:
Václav Šmejkal 2024-02-20 13:45:47 +01:00
parent f3eb26ed59
commit 49b53ec5b1
Signed by: ENGO150
GPG Key ID: 4A57E86482968843
4 changed files with 11 additions and 11 deletions

View File

@ -165,7 +165,7 @@ void *read_socket_raw_thread(void *socket)
void remove_json_syntax_characters(char *text) void remove_json_syntax_characters(char *text)
{ {
for (size_t i = 0; i < strlen(text); i++) //TODO: DO SOMETHING MORE for (int i = 0; text[i] != '\0'; i++) //TODO: DO SOMETHING MORE
{ {
if (text[i] == '\"') if (text[i] == '\"')
{ {
@ -176,7 +176,7 @@ void remove_json_syntax_characters(char *text)
void lowercase(char *string) void lowercase(char *string)
{ {
for (unsigned long i = 0; i < strlen(string); i++) for (int i = 0; string[i] != '\0'; i++)
{ {
string[i] = tolower(string[i]); string[i] = tolower(string[i]);
} }
@ -201,7 +201,7 @@ why2_bool check_username(char *username)
if (username_equal(username, WHY2_CHAT_SERVER_USERNAME)) return 0; //DISABLE 'server' USERNAME if (username_equal(username, WHY2_CHAT_SERVER_USERNAME)) return 0; //DISABLE 'server' USERNAME
if (username_equal(username, WHY2_DEFAULT_USERNAME)) return 0; //DISABLE 'anon' USERNAME DUE TO ONE USERNAME PER SERVER if (username_equal(username, WHY2_DEFAULT_USERNAME)) return 0; //DISABLE 'anon' USERNAME DUE TO ONE USERNAME PER SERVER
for (unsigned long i = 0; i < strlen(username); i++) for (int i = 0; username[i] != '\0'; i++)
{ {
if (!((username[i] >= 48 && username[i] <= 57) || if (!((username[i] >= 48 && username[i] <= 57) ||
(username[i] >= 65 && username[i] <= 90) || //CHECK ONLY FOR a-Z & 0-9 (username[i] >= 65 && username[i] <= 90) || //CHECK ONLY FOR a-Z & 0-9
@ -488,7 +488,7 @@ void *why2_communicate_thread(void *arg)
raw_output = why2_strdup(""); raw_output = why2_strdup("");
//REMOVE CONTROL CHARACTERS FROM raw //REMOVE CONTROL CHARACTERS FROM raw
for (size_t i = 0; i < strlen(raw); i++) for (int i = 0; raw[i] != '\0'; i++)
{ {
if (raw[i] == '\\') raw[i] = '/'; if (raw[i] == '\\') raw[i] = '/';
} }

View File

@ -70,7 +70,7 @@ why2_output_flags why2_decrypt_text(char *text, char *keyNew)
char *used_text = why2_strdup(text); //COPY text TO used_text char *used_text = why2_strdup(text); //COPY text TO used_text
//GET LENGTH OF returningText AND textKeyChain //GET LENGTH OF returningText AND textKeyChain
for (int i = 0; i < (int) strlen(used_text); i++) for (int i = 0; used_text[i] != '\0'; i++)
{ {
if (used_text[i] == why2_get_encryption_separator()) numberBuffer++; if (used_text[i] == why2_get_encryption_separator()) numberBuffer++;
} }
@ -90,7 +90,7 @@ why2_output_flags why2_decrypt_text(char *text, char *keyNew)
numberBuffer = 0; numberBuffer = 0;
//GET LENGTH OF EACH CHARACTER //GET LENGTH OF EACH CHARACTER
for (int j = 0; j < (int) strlen(used_text); j++) for (int j = 0; used_text[i] != '\0'; j++)
{ {
if (used_text[j] == why2_get_encryption_separator()) break; if (used_text[j] == why2_get_encryption_separator()) break;
@ -106,7 +106,7 @@ why2_output_flags why2_decrypt_text(char *text, char *keyNew)
} }
//LOAD textBuffer //LOAD textBuffer
for (int j = 0; j < (int) strlen(used_text); j++) for (int j = 0; used_text[i] != '\0'; j++)
{ {
textBuffer[j] = used_text[j]; textBuffer[j] = used_text[j];

View File

@ -79,13 +79,13 @@ why2_output_flags why2_encrypt_text(char *text, char *keyNew)
why2_generate_text_key_chain(key, textKeyChain, strlen(text)); why2_generate_text_key_chain(key, textKeyChain, strlen(text));
//ACTUALLY ENCRYPT TEXT //ACTUALLY ENCRYPT TEXT
for (int i = 0; i < (int) strlen(text); i++) for (int i = 0; text[i] != '\0'; i++)
{ {
textKeyChain[i] = why2_get_encryption_operation()(textKeyChain[i], (int) text[i]); textKeyChain[i] = why2_get_encryption_operation()(textKeyChain[i], (int) text[i]);
} }
//COUNT REQUIRED SIZE FOR returningText //COUNT REQUIRED SIZE FOR returningText
for (int i = 0; i < (int) strlen(text); i++) for (int i = 0; text[i] != '\0'; i++)
{ {
numberBuffer += why2_count_int_length(textKeyChain[i]); numberBuffer += why2_count_int_length(textKeyChain[i]);
} }
@ -94,7 +94,7 @@ why2_output_flags why2_encrypt_text(char *text, char *keyNew)
returningText = why2_calloc(numberBuffer + strlen(text), sizeof(char)); returningText = why2_calloc(numberBuffer + strlen(text), sizeof(char));
//LOAD returningText //LOAD returningText
for (int i = 0; i < (int) strlen(text); i++) for (int i = 0; text[i] != '\0'; i++)
{ {
numberBuffer = sizeof(int) * why2_count_int_length(textKeyChain[i]); numberBuffer = sizeof(int) * why2_count_int_length(textKeyChain[i]);

View File

@ -119,7 +119,7 @@ void why2_write_log(int loggerFile, char *logMessage)
//COPY logMessage without '\n' //COPY logMessage without '\n'
char *logMessageUsed = why2_strdup(logMessage); char *logMessageUsed = why2_strdup(logMessage);
for (int i = 0; i < (int) strlen(logMessageUsed); i++) for (int i = 0; logMessageUsed[i] != '\0'; i++)
{ {
if (logMessageUsed[i] == '\n') logMessageUsed[i] = '\0'; if (logMessageUsed[i] == '\n') logMessageUsed[i] = '\0';
} }