commit: b61883a7672368b1e7b6c6a4b5b54a38193f803f
parent b8bd2cabd1671d6de244fb0cefe009fd7769b20e
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Fri, 30 Aug 2024 10:05:55 +0200
cmd/base64: Use for-loop on b64_encmap instead of strchr
Fixes the following GCC warning:
cmd/base64.c: In function 'decode':
cmd/base64.c:164:35: warning: 'strchr' argument missing terminating nul [-Wstringop-overread]
164 | const char *pos = strchr(b64_encmap, c);
| ^~~~~~~~~~~~~~~~~~~~~
Diffstat:
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/cmd/base64.c b/cmd/base64.c
@@ -161,16 +161,21 @@ decode(FILE *fin, const char *name)
if(c == '=') break;
- const char *pos = strchr(b64_encmap, c);
- if(pos == NULL)
+ uint8_t b = 65;
+ for(uint8_t i = 0; i < 64; i++)
+ {
+ if(b64_encmap[i] == c)
+ {
+ b = i;
+ break;
+ }
+ }
+ if(b > 64)
{
fprintf(stderr, "base64: Invalid character %c\n", c);
return 1;
}
- uint8_t b = (uint8_t)(pos - b64_encmap);
- assert(b <= 64);
-
//fprintf(stderr, "state: %d | c: %c (%d) | b: %d\n", state, c, c, b);
switch(state)