diff options
author | dzwdz | 2022-04-12 19:44:38 +0200 |
---|---|---|
committer | dzwdz | 2022-04-12 19:44:38 +0200 |
commit | 008ac1574e127162f095a75f63c4c1be5d03b6d0 (patch) | |
tree | 23c7d249ec1e7b3ca85562a0e4a62a9221fb298c /src/kernel/util.h | |
parent | 75ec633805db108bfddb6454ff7f8d812475feaf (diff) |
kernel: make all sizes unsigned, sort out the sign mess
Diffstat (limited to 'src/kernel/util.h')
-rw-r--r-- | src/kernel/util.h | 6 |
1 files changed, 6 insertions, 0 deletions
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 <stddef.h> +#include <stdint.h> #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); +} |