diff options
author | Thomas Voss <mail@thomasvoss.com> | 2023-11-16 21:16:34 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2023-11-16 21:16:34 +0100 |
commit | 296450a16c110c86c890ef98c2c0da403cf96876 (patch) | |
tree | 8da8544da2713c1361a1fa5716afee9cb0d5038f | |
parent | d0acd88463bfe912577a0c0054b948b685384f39 (diff) |
Silence compiler warnings
-rw-r--r-- | Makefile | 9 | ||||
-rw-r--r-- | b32.c | 5 | ||||
-rw-r--r-- | b32.h | 1 | ||||
-rw-r--r-- | main.c | 27 |
4 files changed, 24 insertions, 18 deletions
@@ -1,7 +1,10 @@ CC = cc -CFLAGS = -Wall -Wextra -Wpedantic -Werror \ - -O3 -march=native -mtune=native \ - -fomit-frame-pointer -pipe +CFLAGS = \ + -Wall -Wextra -pedantic -Wshadow -Wpointer-arith -Wcast-align \ + -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations \ + -Wredundant-decls -Wnested-externs -Winline -Wno-long-long \ + -Wconversion -Wstrict-prototypes \ + -O3 -march=native -mtune=native -pipe LDLIBS = -luriparser -lssl -lcrypto PREFIX = /usr/local @@ -2,6 +2,10 @@ #include <stddef.h> #include <stdint.h> +#include "b32.h" + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wsign-conversion" static const uint8_t ctov[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, @@ -20,6 +24,7 @@ static const uint8_t ctov[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, }; +#pragma GCC diagnostic pop bool b32toa(uint8_t *dst, const char *src, size_t len) @@ -2,6 +2,7 @@ #define B32_B32_H #include <stdbool.h> +#include <stddef.h> #include <stdint.h> bool b32toa(uint8_t *, const char *, size_t); @@ -30,18 +30,17 @@ typedef unsigned char uchar; struct totp_config { const char *enc_sec; - long len, p; + long len, p; }; extern char *__progname; static int rv; -static const char *bad_scheme = "Invalid scheme ‘%.*s’; expected ‘otpauth’"; -static const char *bad_param = "Invalid ‘%s’ parameter provided"; +static const char *bad_scheme = "Invalid scheme ‘%.*s’; expected ‘otpauth’"; +static const char *bad_param = "Invalid ‘%s’ parameter provided"; static const char *empty_param = "Empty ‘%s’ parameter provided"; -static const char *usage_s = - "Usage: %s [-d digits] [-p period] [-u] [secret ...]\n"; +static const char *usage_s = "Usage: %s [-d digits] [-p period] [-u] [secret ...]\n"; static void usage(void); static void totp_print(struct totp_config, char *, bool); @@ -141,13 +140,13 @@ uri_parse(struct totp_config *conf, const char *uri_raw) const char *epos; if (uriParseSingleUriA(&uri, uri_raw, &epos) != URI_SUCCESS) { - len = epos - uri_raw + 24 + strlen(__progname); + len = (size_t)(epos - uri_raw) + 24 + strlen(__progname); WARNX_AND_RET("Failed to parse URI ‘%s’\n" "%*c Error detected here", uri_raw, (int)len, '^'); } - len = uri.scheme.afterLast - uri.scheme.first; + len = (size_t)(uri.scheme.afterLast - uri.scheme.first); reject = len != strlen("otpauth"); reject = reject || strncasecmp(uri.scheme.first, "otpauth", len) != 0; @@ -209,7 +208,7 @@ totp(struct totp_config conf, uint32_t *code) clean = true; } - keylen = old / 1.6; + keylen = (size_t)((double)old / 1.6); if ((key = calloc(keylen + 1, sizeof(char))) == NULL) err(EXIT_FAILURE, "calloc"); b32toa(key, enc_sec, enc_sec_len); @@ -223,12 +222,10 @@ totp(struct totp_config conf, uint32_t *code) if (big_endian()) memcpy(buf, &epoch, sizeof(time_t)); - else { - for (size_t i = 0; i < sizeof(buf); i++) - buf[i] = (epoch >> (8 * (sizeof(buf) - 1 - i))) & 0xFF; - } + else for (size_t i = sizeof(buf); i --> 0;) + buf[sizeof(buf)-1-i] = (uint8_t)((epoch >> 8 * i) & 0xFF); - mac = HMAC(EVP_sha1(), key, keylen, buf, sizeof(buf), NULL, NULL); + mac = HMAC(EVP_sha1(), key, (int)keylen, buf, sizeof(buf), NULL, NULL); if (mac == NULL) WARNX_AND_RET("Failed to compute HMAC SHA-1 hash"); @@ -238,7 +235,7 @@ totp(struct totp_config conf, uint32_t *code) | (mac[off + 1] & 0xFF) << 16 | (mac[off + 2] & 0xFF) << 8 | (mac[off + 3] & 0xFF) << 0; - *code = binc % pow32(10, conf.len); + *code = binc % pow32(10, (uint32_t)conf.len); if (clean) free(enc_sec); @@ -258,7 +255,7 @@ strtol_safe(long *n, const char *s) uint32_t pow32(uint32_t x, uint32_t y) { - int n = x; + uint32_t n = x; if (y == 0) return 1; while (--y != 0) |