From 383c232bc2f1661923177437e48ea4cf6bd4e304 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Sun, 7 Nov 2021 22:18:21 +0000 Subject: use safe_islower to avoid UB --- common.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'common.h') diff --git a/common.h b/common.h index abef5af..ed4b05e 100644 --- a/common.h +++ b/common.h @@ -7,6 +7,7 @@ #include #include +#include #include "pack.h" @@ -39,6 +40,13 @@ T(LLONG, signed, long long, long long) \ T(ULLONG, unsigned, long long, long long) +// safe_islower: islower but no domain errors +static inline int safe_islower(int c) +{ + if (c < 0 || c > UCHAR_MAX) return 0; + return islower(c); +} + size_t getsize(enum pack_type t); #endif // !PACK_COMMON_H -- cgit v1.2.3-54-g00ecf