From: Scott Worley Date: Wed, 13 Sep 2023 18:40:48 +0000 (-0700) Subject: appease clang-tidy: Careful of size_t→int narrowing conversion X-Git-Tag: v1.0.0~12 X-Git-Url: http://git.scottworley.com/tl-append/commitdiff_plain/90df84eb2e05926351cc7df661712c97779c9163 appease clang-tidy: Careful of size_t→int narrowing conversion Why does fgets take an int instead of a size_t? :( --- diff --git a/tl-append-test.c b/tl-append-test.c index 4d51c38..08cf800 100644 --- a/tl-append-test.c +++ b/tl-append-test.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -89,6 +90,8 @@ static void verify_log_contents(ex_t exps[]) { die_err("Error opening log file"); for (size_t i = 0; !is_end(exps[i]); i++) { size_t len = TIMESTAMP_LEN + 1 + strlen(exps[i].message); + if (len > INT_MAX - 1) + die("message too long"); char *buf = (char *)malloc(len + 2); if (fgets(buf, len + 1, f) == NULL) die("Error reading log file");