From 008ac1574e127162f095a75f63c4c1be5d03b6d0 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Tue, 12 Apr 2022 19:44:38 +0200 Subject: kernel: make all sizes unsigned, sort out the sign mess --- src/kernel/util.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/kernel/util.h') diff --git a/src/kernel/util.h b/src/kernel/util.h index 9b8cb3d..0e57d67 100644 --- a/src/kernel/util.h +++ b/src/kernel/util.h @@ -1,5 +1,6 @@ #pragma once #include +#include #define __NUM2STR(x) #x #define NUM2STR(x) __NUM2STR(x) @@ -13,3 +14,8 @@ typeof (a) _a = (a); \ typeof (b) _b = (b); \ _a > _b ? _a : _b; }) + +/* casts an uint32_t to int32_t, capping it at INT32_MAX instead of overflowing */ +static inline int32_t capped_cast32(uint32_t u) { + return (int32_t)min(u, (uint32_t)INT32_MAX); +} -- cgit v1.2.3