From 618262d2a2ae31a084600955c49f0629a231af4f Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Tue, 13 Dec 2022 20:25:35 +0000 Subject: [PATCH] cleaup: cleanup code. --- plugins/libre_redirect/example | Bin 17040 -> 17040 bytes plugins/libre_redirect/libre_redirect.c | 6 +----- plugins/libre_redirect/str_replace_start.c | 12 ++++++------ 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/plugins/libre_redirect/example b/plugins/libre_redirect/example index bb0a7a73ab7f4f590fa0fec4287eaae9564dcbb8..4e80ab8de8e1f4e5d83ca5e1deec790da9c868d3 100755 GIT binary patch delta 42 zcmV+_0M-AHg#nO-0kCKT6o_1)#FV~mso=QhY*SLu!T-U6?6Z6WlN int libre_redirect(const char* uri, char* output){ - /* inv.riverside.rocks */ - // max length int l1 = strlen(uri); int l2 = strlen(output); @@ -23,7 +19,7 @@ int libre_redirect(const char* uri, char* output){ return 1; // not enough memory. }else{ char tmp_uri[l2++]; - strcpy(tmp_uri, uri); // includes terminating '\0' + strcpy(tmp_uri, uri); // strcpy also copies the terminating '\0' char* sites[] = { "https://youtube.com", diff --git a/plugins/libre_redirect/str_replace_start.c b/plugins/libre_redirect/str_replace_start.c index 70f9567..eaa61d3 100755 --- a/plugins/libre_redirect/str_replace_start.c +++ b/plugins/libre_redirect/str_replace_start.c @@ -10,7 +10,7 @@ See also: */ int str_replace_start(const char* string, const char* target, const char* replacement, char* output){ - /* Checks */ + int l1 = strlen(string); int l2 = strlen(target); int l3 = strlen(replacement); @@ -19,16 +19,16 @@ int str_replace_start(const char* string, const char* target, const char* replac if((l4 < (l1 - l2 + l3)) || l4 < l1 ){ // Not enough memory in output string. - if(DEBUG) printf("Case 1.\n"); + if(DEBUG) printf("String not long enough.\n"); return 1; } else if(l1 < l2){ // Not even possible that there is a match. - if(DEBUG) printf("Case 2.\n"); + if(DEBUG) printf("Target larger than string.\n"); strcpy(output, string); } else { - if(DEBUG) printf("Case 3.\n"); + if(DEBUG) printf("Looking for a match.\n"); int match = true; for(int i=0; i