summaryrefslogtreecommitdiff
path: root/nasmlib.h
diff options
context:
space:
mode:
Diffstat (limited to 'nasmlib.h')
-rw-r--r--nasmlib.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/nasmlib.h b/nasmlib.h
index 689485b..441ea20 100644
--- a/nasmlib.h
+++ b/nasmlib.h
@@ -383,4 +383,31 @@ const char *prefix_name(int);
extern const uint8_t zero_buffer[ZERO_BUF_SIZE];
size_t fwritezero(size_t bytes, FILE *fp);
+static inline bool overflow_general(int64_t value, int bytes)
+{
+ int sbit = (bytes << 3) - 1;
+ int64_t vmax = ((int64_t)2 << sbit) - 1;
+ int64_t vmin = -((int64_t)1 << sbit);
+
+ return value < vmin || value > vmax;
+}
+
+static inline bool overflow_signed(int64_t value, int bytes)
+{
+ int sbit = (bytes << 3) - 1;
+ int64_t vmax = ((int64_t)1 << sbit) - 1;
+ int64_t vmin = -((int64_t)1 << sbit);
+
+ return value < vmin || value > vmax;
+}
+
+static inline bool overflow_unsigned(int64_t value, int bytes)
+{
+ int sbit = (bytes << 3) - 1;
+ int64_t vmax = ((int64_t)2 << sbit) - 1;
+ int64_t vmin = 0;
+
+ return value < vmin || value > vmax;
+}
+
#endif