The cirros image was rebuilt against the 3.13.0-83 kernel, drivers e1000e, igbvf...
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / buildroot-2015.05 / package / uclibc / 0.9.33.2 / 0042-nice-fix-overflow-checking-in-int_add_no_wrap.patch
1 From e6735556ed0a5e791ea81a015a90c130a0eea060 Mon Sep 17 00:00:00 2001
2 From: Xi Wang <xi@mit.edu>
3 Date: Wed, 20 Feb 2013 12:45:45 -0500
4 Subject: [PATCH] nice: fix overflow checking in int_add_no_wrap()
5
6 In C, signed integer overflow is undefined behavior.  Many compilers
7 optimize away checks like `a + b < a'.
8
9 Use safe precondition testing instead.
10
11 Signed-off-by: Xi Wang <xi@mit.edu>
12 Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
13 ---
14  libc/sysdeps/linux/common/nice.c |   10 +++++-----
15  1 file changed, 5 insertions(+), 5 deletions(-)
16
17 diff --git a/libc/sysdeps/linux/common/nice.c b/libc/sysdeps/linux/common/nice.c
18 index 3694db8..ed39946 100644
19 --- a/libc/sysdeps/linux/common/nice.c
20 +++ b/libc/sysdeps/linux/common/nice.c
21 @@ -25,15 +25,15 @@ static __inline__ _syscall1(int, __syscall_nice, int, incr)
22  
23  static __inline__ int int_add_no_wrap(int a, int b)
24  {
25 -       int s = a + b;
26 -
27         if (b < 0) {
28 -               if (s > a) s = INT_MIN;
29 +               if (a < INT_MIN - b)
30 +                       return INT_MIN;
31         } else {
32 -               if (s < a) s = INT_MAX;
33 +               if (a > INT_MAX - b)
34 +                       return INT_MAX;
35         }
36  
37 -       return s;
38 +       return a + b;
39  }
40  
41  static __inline__ int __syscall_nice(int incr)
42 -- 
43 1.7.10.4
44