X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=cirros-testvm%2Fsrc-cirros%2Fbuildroot-2015.05%2Fpackage%2Fuclibc%2F0.9.33.2%2F0042-nice-fix-overflow-checking-in-int_add_no_wrap.patch;fp=cirros-testvm%2Fsrc-cirros%2Fbuildroot-2015.05%2Fpackage%2Fuclibc%2F0.9.33.2%2F0042-nice-fix-overflow-checking-in-int_add_no_wrap.patch;h=a6e6349cb8bee1d777242f0133ea040cfa0b577d;hb=b0a0f15dfaa205161a7fcb20cf1b8cd4948c2ef3;hp=0000000000000000000000000000000000000000;hpb=c6ac3cd55ee2da956195eee393b0882105dfad4e;p=packages%2Ftrusty%2Fcirros-testvm.git diff --git a/cirros-testvm/src-cirros/buildroot-2015.05/package/uclibc/0.9.33.2/0042-nice-fix-overflow-checking-in-int_add_no_wrap.patch b/cirros-testvm/src-cirros/buildroot-2015.05/package/uclibc/0.9.33.2/0042-nice-fix-overflow-checking-in-int_add_no_wrap.patch new file mode 100644 index 0000000..a6e6349 --- /dev/null +++ b/cirros-testvm/src-cirros/buildroot-2015.05/package/uclibc/0.9.33.2/0042-nice-fix-overflow-checking-in-int_add_no_wrap.patch @@ -0,0 +1,44 @@ +From e6735556ed0a5e791ea81a015a90c130a0eea060 Mon Sep 17 00:00:00 2001 +From: Xi Wang +Date: Wed, 20 Feb 2013 12:45:45 -0500 +Subject: [PATCH] nice: fix overflow checking in int_add_no_wrap() + +In C, signed integer overflow is undefined behavior. Many compilers +optimize away checks like `a + b < a'. + +Use safe precondition testing instead. + +Signed-off-by: Xi Wang +Signed-off-by: Bernhard Reutner-Fischer +--- + libc/sysdeps/linux/common/nice.c | 10 +++++----- + 1 file changed, 5 insertions(+), 5 deletions(-) + +diff --git a/libc/sysdeps/linux/common/nice.c b/libc/sysdeps/linux/common/nice.c +index 3694db8..ed39946 100644 +--- a/libc/sysdeps/linux/common/nice.c ++++ b/libc/sysdeps/linux/common/nice.c +@@ -25,15 +25,15 @@ static __inline__ _syscall1(int, __syscall_nice, int, incr) + + static __inline__ int int_add_no_wrap(int a, int b) + { +- int s = a + b; +- + if (b < 0) { +- if (s > a) s = INT_MIN; ++ if (a < INT_MIN - b) ++ return INT_MIN; + } else { +- if (s < a) s = INT_MAX; ++ if (a > INT_MAX - b) ++ return INT_MAX; + } + +- return s; ++ return a + b; + } + + static __inline__ int __syscall_nice(int incr) +-- +1.7.10.4 +