diff --git a/CHANGES b/CHANGES index 2b5acf7..a31da4f 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,7 @@ add fmt_strm add iob_addbuf_munmap add socket_deferaccept + catch one more case in umult64 (Tomi Jylhä-Ollila) 0.26: fix really pathological case where io_timeouted would never diff --git a/mult/umult64.c b/mult/umult64.c index 82bf2ab..b6a53f4 100644 --- a/mult/umult64.c +++ b/mult/umult64.c @@ -37,7 +37,11 @@ int umult64(uint64 a,uint64 b,uint64* c) { a=(uint64)(ahi)*blo+(uint64)(alo)*bhi; if (a>0xffffffff) return 0; - *c=(a<<32)+(uint64)(alo)*blo; + { + uint64 x=(uint64)(alo)*blo; + if (x+(a<<32) < x) return 0; + *c=x+(a<<32); + } return 1; } diff --git a/test/mult.c b/test/mult.c index c772db0..9fd23f2 100644 --- a/test/mult.c +++ b/test/mult.c @@ -19,5 +19,7 @@ int main() { assert(imult64(-0x4000000000000000ll,2,&c)==1 && c==(int64)-0x8000000000000000ll); assert(imult64(0x3fffffffffffffffll,2,&c)==1 && c==0x7ffffffffffffffell); + assert(umult64(0x0000000100000002ull,0x00000000ffffffffull,&c)==0); + return 0; } diff --git a/va_narg.h b/va_narg.h index e64fc8b..58a6355 100644 --- a/va_narg.h +++ b/va_narg.h @@ -30,4 +30,7 @@ 19,18,17,16,15,14,13,12,11,10, \ 9,8,7,6,5,4,3,2,1,0 +#define COUNT(x, ...) ({ typeof (x) __fnord[] = { x, __VA_ARGS__ }; sizeof(__fnord)/sizeof(__fnord[0]); }) +#define COUNT_PREFIX(x, ...) ({ typeof (x) __fnord[] = { x, __VA_ARGS__ }; sizeof(__fnord)/sizeof(__fnord[0]); }), x, __VA_ARGS__ + #endif