nightmaremail

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 105e01c5cbdd7f042043f595794f12ff8664dda3
parent edf54c818e5549026098acd95ae44f0ddf6a7722
Author: Rolf Eike Beer <eike@sf-mail.de>
Date:   Sun, 10 May 2020 15:28:09 +0200

add compat version of __builtin_{add,mul}_overflow()

Diffstat:
MMakefile | 23+++++++++++++++--------
MTARGETS | 1+
Achkbiofl.c | 5+++++
Aoflops_bi.h | 6++++++
Aoflops_compat.h | 27+++++++++++++++++++++++++++
5 files changed, 54 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile @@ -772,7 +772,7 @@ compile ip.c fmt.h scan.h ip.h ipalloc.o: \ compile ipalloc.c alloc.h gen_allocdefs.h ip.h ipalloc.h ip.h \ -gen_alloc.h +gen_alloc.h oflops.h ./compile ipalloc.c ipme.o: \ @@ -954,6 +954,13 @@ now.o: \ compile now.c datetime.h now.h datetime.h ./compile now.c +oflops.h: \ +chkbiofl.c compile load oflops_bi.h oflops_compat.h + ( ( ./compile chkbiofl.c && ./load chkbiofl && \ + ./chkbiofl ) >/dev/null 2>&1 \ + && cat oflops_bi.h || cat oflops_compat.h ) > oflops.h + rm -f chkbiofl.o chkbiofl + open.a: \ makelib open_append.o open_excl.o open_read.o open_trunc.o \ open_write.o @@ -1020,7 +1027,7 @@ substdio.h exit.h fork.h wait.h env.h sig.h error.h prioq.o: \ compile prioq.c alloc.h gen_allocdefs.h prioq.h datetime.h \ -gen_alloc.h +gen_alloc.h oflops.h ./compile prioq.c proc: \ @@ -1139,7 +1146,7 @@ compile qmail-inject.c sig.h substdio.h stralloc.h gen_alloc.h \ subfd.h substdio.h sgetopt.h subgetopt.h getln.h alloc.h str.h fmt.h \ hfield.h token822.h gen_alloc.h control.h env.h gen_alloc.h \ gen_allocdefs.h error.h qmail.h substdio.h now.h datetime.h exit.h \ -quote.h headerbody.h auto_qmail.h newfield.h stralloc.h constmap.h +quote.h headerbody.h auto_qmail.h newfield.h stralloc.h constmap.h oflops.h ./compile qmail-inject.c qmail-limits.0: \ @@ -1428,7 +1435,7 @@ compile qmail-remote.c sig.h stralloc.h gen_alloc.h substdio.h \ subfd.h substdio.h scan.h case.h error.h auto_qmail.h control.h dns.h \ alloc.h quote.h ip.h ipalloc.h ip.h gen_alloc.h ipme.h ip.h ipalloc.h \ gen_alloc.h gen_allocdefs.h str.h now.h datetime.h exit.h constmap.h \ -tcpto.h readwrite.h timeoutconn.h timeoutread.h timeoutwrite.h +tcpto.h readwrite.h timeoutconn.h timeoutread.h timeoutwrite.h oflops.h ./compile qmail-remote.c qmail-rspawn: \ @@ -1624,7 +1631,7 @@ qreceipt.o: \ compile qreceipt.c sig.h env.h substdio.h stralloc.h gen_alloc.h \ subfd.h substdio.h getln.h alloc.h str.h hfield.h token822.h \ gen_alloc.h error.h gen_alloc.h gen_allocdefs.h headerbody.h exit.h \ -open.h quote.h qmail.h substdio.h +open.h quote.h qmail.h substdio.h oflops.h ./compile qreceipt.c qsmhook: \ @@ -1876,7 +1883,7 @@ compile stralloc_copy.c byte.h stralloc.h gen_alloc.h stralloc_eady.o: \ compile stralloc_eady.c alloc.h stralloc.h gen_alloc.h \ -gen_allocdefs.h +gen_allocdefs.h oflops.h ./compile stralloc_eady.c stralloc_opyb.o: \ @@ -1889,7 +1896,7 @@ compile stralloc_opys.c byte.h str.h stralloc.h gen_alloc.h stralloc_pend.o: \ compile stralloc_pend.c alloc.h stralloc.h gen_alloc.h \ -gen_allocdefs.h +gen_allocdefs.h oflops.h ./compile stralloc_pend.c strerr.a: \ @@ -2005,7 +2012,7 @@ compile timeoutwrite.c timeoutwrite.h select.h error.h readwrite.h token822.o: \ compile token822.c stralloc.h gen_alloc.h alloc.h str.h token822.h \ -gen_alloc.h gen_allocdefs.h +gen_alloc.h gen_allocdefs.h oflops.h ./compile token822.c trigger.o: \ diff --git a/TARGETS b/TARGETS @@ -25,6 +25,7 @@ subgetopt.o sgetopt.o getopt.a sig_alarm.o +oflops.h hassgprm.h sig_block.o hassgact.h diff --git a/chkbiofl.c b/chkbiofl.c @@ -0,0 +1,5 @@ +int main() +{ + unsigned int a = 0x80000000, b = 0x80000000, c; + return !__builtin_add_overflow(a, b, &c) && !__builtin_mul_overflow(a, b, &c); +} diff --git a/oflops_bi.h b/oflops_bi.h @@ -0,0 +1,6 @@ +#ifndef OFLOPS_H +#define OFLOPS_H + +/* this header is intentionally empty, compiler builtins are used. */ + +#endif /* OFLOPS_H */ diff --git a/oflops_compat.h b/oflops_compat.h @@ -0,0 +1,27 @@ +#ifndef OFLOPS_H +#define OFLOPS_H + +static inline int check_ofl(unsigned long long val, unsigned int *res) +{ + if (val >> 32) + return 1; + *res = (unsigned int)val; + return 0; +} + +static inline int __builtin_add_overflow(unsigned int a, unsigned int b, unsigned int *res) +{ + unsigned long long val = a; + val += b; + return check_ofl(val, res); +} + +static inline int __builtin_mul_overflow(unsigned int a, unsigned int b, unsigned int *res) +{ + unsigned long long val = a; + val *= b; + return check_ofl(val, res); +} + +#endif /* OFLOPS_H */ +