diff --git a/plugins/libre_redirect/example b/plugins/libre_redirect/example index bb0a7a7..4e80ab8 100755 Binary files a/plugins/libre_redirect/example and b/plugins/libre_redirect/example differ diff --git a/plugins/libre_redirect/libre_redirect.c b/plugins/libre_redirect/libre_redirect.c index b64b715..59ee2fb 100644 --- a/plugins/libre_redirect/libre_redirect.c +++ b/plugins/libre_redirect/libre_redirect.c @@ -4,8 +4,6 @@ /* Inspired by https://libredirect.github.io/, but in C. */ -// int str_replace_start(const char* string, const char* target, const char* replacement, char* output){ - void str_init(char* str, int n){ for(int i=0; i 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