tweak: fix off-by-one error.

This commit is contained in:
NunoSempere 2022-12-13 22:31:21 +00:00
parent a6835ab2ae
commit d3caecab58
3 changed files with 8 additions and 7 deletions

View File

@ -30,7 +30,7 @@
#define ZOOM 1.4 /* Starting zoom level.*/ #define ZOOM 1.4 /* Starting zoom level.*/
#define ZOOM_VAL .1 /* Zooming value in zoomin/zoomout functions */ #define ZOOM_VAL .1 /* Zooming value in zoomin/zoomout functions */
#define BG_COLOR "#FEFEFE" /*"#1E1E2E" */ #define BG_COLOR "#FEFEFE" /*"#1E1E2E" */
#define DEBUG false #define DEBUG true
typedef enum { typedef enum {
goback, goback,

View File

@ -3,7 +3,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#define LIBRE_N 12 #define LIBRE_N 12
#define DEBUG false #define DEBUG true
/* Inspired by https://libredirect.github.io/, but in C. */ /* Inspired by https://libredirect.github.io/, but in C. */
@ -40,7 +40,7 @@ int libre_redirect(const char* uri, char* output){
"https://simplytranslate.org/" "https://simplytranslate.org/"
}; };
for(int i=1; i<4; i++){ for(int i=0; i<4; i++){
int replace_check = str_replace_start(tmp_uri, sites[i], alternatives[i], output); int replace_check = str_replace_start(tmp_uri, sites[i], alternatives[i], output);
if(replace_check == 2){ if(replace_check == 2){
if(DEBUG) printf("tmp_uri: %s\n", tmp_uri); if(DEBUG) printf("tmp_uri: %s\n", tmp_uri);
@ -57,7 +57,7 @@ int libre_redirect(const char* uri, char* output){
} }
strcpy(output, tmp_uri); strcpy(output, tmp_uri);
} }
if(DEBUG) printf("No match found\n\n");
return 0; return 0;
} }

View File

@ -1,7 +1,7 @@
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#define DEBUG false #define DEBUG true
/* /*
See also: See also:
@ -16,17 +16,18 @@ int str_replace_start(const char* string, const char* target, const char* replac
int l3 = strlen(replacement); int l3 = strlen(replacement);
int l4 = strlen(output); int l4 = strlen(output);
if(DEBUG) printf("%d,%d,%d,%d\n", l1, l2, l3, l4); if(DEBUG) printf("%d,%d,%d,%d\n", l1, l2, l3, l4);
// if(DEBUG) printf("%s,%s,%s,%s\n", string, target, replacement, output);
if((l4 < (l1 - l2 + l3)) || l4 < l1 ){ if((l4 < (l1 - l2 + l3)) || l4 < l1 ){
// Not enough memory in output string. // Not enough memory in output string.
if(DEBUG) printf("String not long enough.\n"); if(DEBUG) printf("String not long enough.\n");
return 1; return 1;
} }
else if(l1 < l2){ /* else if(l1 < l2){
// Not even possible that there is a match. // Not even possible that there is a match.
if(DEBUG) printf("Target larger than string.\n"); if(DEBUG) printf("Target larger than string.\n");
strcpy(output, string); strcpy(output, string);
} } */
else { else {
if(DEBUG) printf("Looking for a match for %s in %s.\n", target, string); if(DEBUG) printf("Looking for a match for %s in %s.\n", target, string);
int match = true; int match = true;