Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 617538
Collapse All | Expand All

(-)diffutils-3.5/lib/intprops.h.than (-22 / +35 lines)
Lines 1-6 Link Here
1
/* intprops.h -- properties of integer types
1
/* intprops.h -- properties of integer types
2
2
3
   Copyright (C) 2001-2016 Free Software Foundation, Inc.
3
   Copyright (C) 2001-2017 Free Software Foundation, Inc.
4
4
5
   This program is free software: you can redistribute it and/or modify it
5
   This program is free software: you can redistribute it and/or modify it
6
   under the terms of the GNU General Public License as published
6
   under the terms of the GNU General Public License as published
Lines 47-58 Link Here
47
47
48
/* Minimum and maximum values for integer types and expressions.  */
48
/* Minimum and maximum values for integer types and expressions.  */
49
49
50
/* The width in bits of the integer type or expression T.
51
   Padding bits are not supported; this is checked at compile-time below.  */
52
#define TYPE_WIDTH(t) (sizeof (t) * CHAR_BIT)
53
50
/* The maximum and minimum values for the integer type T.  */
54
/* The maximum and minimum values for the integer type T.  */
51
#define TYPE_MINIMUM(t) ((t) ~ TYPE_MAXIMUM (t))
55
#define TYPE_MINIMUM(t) ((t) ~ TYPE_MAXIMUM (t))
52
#define TYPE_MAXIMUM(t)                                                 \
56
#define TYPE_MAXIMUM(t)                                                 \
53
  ((t) (! TYPE_SIGNED (t)                                               \
57
  ((t) (! TYPE_SIGNED (t)                                               \
54
        ? (t) -1                                                        \
58
        ? (t) -1                                                        \
55
        : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1)))
59
        : ((((t) 1 << (TYPE_WIDTH (t) - 2)) - 1) * 2 + 1)))
56
60
57
/* The maximum and minimum values for the type of the expression E,
61
/* The maximum and minimum values for the type of the expression E,
58
   after integer promotion.  E should not have side effects.  */
62
   after integer promotion.  E should not have side effects.  */
Lines 65-71 Link Here
65
   ? _GL_SIGNED_INT_MAXIMUM (e)                                         \
69
   ? _GL_SIGNED_INT_MAXIMUM (e)                                         \
66
   : _GL_INT_NEGATE_CONVERT (e, 1))
70
   : _GL_INT_NEGATE_CONVERT (e, 1))
67
#define _GL_SIGNED_INT_MAXIMUM(e)                                       \
71
#define _GL_SIGNED_INT_MAXIMUM(e)                                       \
68
  (((_GL_INT_CONVERT (e, 1) << (sizeof ((e) + 0) * CHAR_BIT - 2)) - 1) * 2 + 1)
72
  (((_GL_INT_CONVERT (e, 1) << (TYPE_WIDTH ((e) + 0) - 2)) - 1) * 2 + 1)
73
74
/* Work around OpenVMS incompatibility with C99.  */
75
#if !defined LLONG_MAX && defined __INT64_MAX
76
# define LLONG_MAX __INT64_MAX
77
# define LLONG_MIN __INT64_MIN
78
#endif
69
79
70
/* This include file assumes that signed types are two's complement without
80
/* This include file assumes that signed types are two's complement without
71
   padding bits; the above macros have undefined behavior otherwise.
81
   padding bits; the above macros have undefined behavior otherwise.
Lines 84-93 verify (TYPE_MAXIMUM (long int) == LONG_ Link Here
84
verify (TYPE_MINIMUM (long long int) == LLONG_MIN);
94
verify (TYPE_MINIMUM (long long int) == LLONG_MIN);
85
verify (TYPE_MAXIMUM (long long int) == LLONG_MAX);
95
verify (TYPE_MAXIMUM (long long int) == LLONG_MAX);
86
#endif
96
#endif
97
/* Similarly, sanity-check one ISO/IEC TS 18661-1:2014 macro if defined.  */
98
#ifdef UINT_WIDTH
99
verify (TYPE_WIDTH (unsigned int) == UINT_WIDTH);
100
#endif
87
101
88
/* Does the __typeof__ keyword work?  This could be done by
102
/* Does the __typeof__ keyword work?  This could be done by
89
   'configure', but for now it's easier to do it by hand.  */
103
   'configure', but for now it's easier to do it by hand.  */
90
#if (2 <= __GNUC__ || defined __IBM__TYPEOF__ \
104
#if (2 <= __GNUC__ \
105
     || (1210 <= __IBMC__ && defined __IBM__TYPEOF__) \
91
     || (0x5110 <= __SUNPRO_C && !__STDC__))
106
     || (0x5110 <= __SUNPRO_C && !__STDC__))
92
# define _GL_HAVE___TYPEOF__ 1
107
# define _GL_HAVE___TYPEOF__ 1
93
#else
108
#else
Lines 116-123 verify (TYPE_MAXIMUM (long long int) == Link Here
116
   signed, this macro may overestimate the true bound by one byte when
131
   signed, this macro may overestimate the true bound by one byte when
117
   applied to unsigned types of size 2, 4, 16, ... bytes.  */
132
   applied to unsigned types of size 2, 4, 16, ... bytes.  */
118
#define INT_STRLEN_BOUND(t)                                     \
133
#define INT_STRLEN_BOUND(t)                                     \
119
  (INT_BITS_STRLEN_BOUND (sizeof (t) * CHAR_BIT                 \
134
  (INT_BITS_STRLEN_BOUND (TYPE_WIDTH (t) - _GL_SIGNED_TYPE_OR_EXPR (t)) \
120
                          - _GL_SIGNED_TYPE_OR_EXPR (t))        \
121
   + _GL_SIGNED_TYPE_OR_EXPR (t))
135
   + _GL_SIGNED_TYPE_OR_EXPR (t))
122
136
123
/* Bound on buffer size needed to represent an integer type or expression T,
137
/* Bound on buffer size needed to represent an integer type or expression T,
Lines 222-241 verify (TYPE_MAXIMUM (long long int) == Link Here
222
   ? (a) < (min) >> (b)                                 \
236
   ? (a) < (min) >> (b)                                 \
223
   : (max) >> (b) < (a))
237
   : (max) >> (b) < (a))
224
238
225
/* True if __builtin_add_overflow (A, B, P) works when P is null.  */
239
/* True if __builtin_add_overflow (A, B, P) works when P is non-null.  */
226
#define _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL (7 <= __GNUC__)
240
#define _GL_HAS_BUILTIN_OVERFLOW (5 <= __GNUC__)
241
242
/* True if __builtin_add_overflow_p (A, B, C) works.  */
243
#define _GL_HAS_BUILTIN_OVERFLOW_P (7 <= __GNUC__)
227
244
228
/* The _GL*_OVERFLOW macros have the same restrictions as the
245
/* The _GL*_OVERFLOW macros have the same restrictions as the
229
   *_RANGE_OVERFLOW macros, except that they do not assume that operands
246
   *_RANGE_OVERFLOW macros, except that they do not assume that operands
230
   (e.g., A and B) have the same type as MIN and MAX.  Instead, they assume
247
   (e.g., A and B) have the same type as MIN and MAX.  Instead, they assume
231
   that the result (e.g., A + B) has that type.  */
248
   that the result (e.g., A + B) has that type.  */
232
#if _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL
249
#if _GL_HAS_BUILTIN_OVERFLOW_P
233
# define _GL_ADD_OVERFLOW(a, b, min, max)
250
# define _GL_ADD_OVERFLOW(a, b, min, max)                               \
234
   __builtin_add_overflow (a, b, (__typeof__ ((a) + (b)) *) 0)
251
   __builtin_add_overflow_p (a, b, (__typeof__ ((a) + (b))) 0)
235
# define _GL_SUBTRACT_OVERFLOW(a, b, min, max)
252
# define _GL_SUBTRACT_OVERFLOW(a, b, min, max)                          \
236
   __builtin_sub_overflow (a, b, (__typeof__ ((a) - (b)) *) 0)
253
   __builtin_sub_overflow_p (a, b, (__typeof__ ((a) - (b))) 0)
237
# define _GL_MULTIPLY_OVERFLOW(a, b, min, max)
254
# define _GL_MULTIPLY_OVERFLOW(a, b, min, max)                          \
238
   __builtin_mul_overflow (a, b, (__typeof__ ((a) * (b)) *) 0)
255
   __builtin_mul_overflow_p (a, b, (__typeof__ ((a) * (b))) 0)
239
#else
256
#else
240
# define _GL_ADD_OVERFLOW(a, b, min, max)                                \
257
# define _GL_ADD_OVERFLOW(a, b, min, max)                                \
241
   ((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max)                  \
258
   ((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max)                  \
Lines 315-321 verify (TYPE_MAXIMUM (long long int) == Link Here
315
  _GL_BINARY_OP_OVERFLOW (a, b, _GL_ADD_OVERFLOW)
332
  _GL_BINARY_OP_OVERFLOW (a, b, _GL_ADD_OVERFLOW)
316
#define INT_SUBTRACT_OVERFLOW(a, b) \
333
#define INT_SUBTRACT_OVERFLOW(a, b) \
317
  _GL_BINARY_OP_OVERFLOW (a, b, _GL_SUBTRACT_OVERFLOW)
334
  _GL_BINARY_OP_OVERFLOW (a, b, _GL_SUBTRACT_OVERFLOW)
318
#if _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL
335
#if _GL_HAS_BUILTIN_OVERFLOW_P
319
# define INT_NEGATE_OVERFLOW(a) INT_SUBTRACT_OVERFLOW (0, a)
336
# define INT_NEGATE_OVERFLOW(a) INT_SUBTRACT_OVERFLOW (0, a)
320
#else
337
#else
321
# define INT_NEGATE_OVERFLOW(a) \
338
# define INT_NEGATE_OVERFLOW(a) \
Lines 349-358 verify (TYPE_MAXIMUM (long long int) == Link Here
349
#define INT_MULTIPLY_WRAPV(a, b, r) \
366
#define INT_MULTIPLY_WRAPV(a, b, r) \
350
  _GL_INT_OP_WRAPV (a, b, r, *, __builtin_mul_overflow, INT_MULTIPLY_OVERFLOW)
367
  _GL_INT_OP_WRAPV (a, b, r, *, __builtin_mul_overflow, INT_MULTIPLY_OVERFLOW)
351
368
352
#ifndef __has_builtin
353
# define __has_builtin(x) 0
354
#endif
355
356
/* Nonzero if this compiler has GCC bug 68193 or Clang bug 25390.  See:
369
/* Nonzero if this compiler has GCC bug 68193 or Clang bug 25390.  See:
357
   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68193
370
   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68193
358
   https://llvm.org/bugs/show_bug.cgi?id=25390
371
   https://llvm.org/bugs/show_bug.cgi?id=25390
Lines 369-375 verify (TYPE_MAXIMUM (long long int) == Link Here
369
   the operation.  BUILTIN is the builtin operation, and OVERFLOW the
382
   the operation.  BUILTIN is the builtin operation, and OVERFLOW the
370
   overflow predicate.  Return 1 if the result overflows.  See above
383
   overflow predicate.  Return 1 if the result overflows.  See above
371
   for restrictions.  */
384
   for restrictions.  */
372
#if 5 <= __GNUC__ || __has_builtin (__builtin_add_overflow)
385
#if _GL_HAS_BUILTIN_OVERFLOW
373
# define _GL_INT_OP_WRAPV(a, b, r, op, builtin, overflow) builtin (a, b, r)
386
# define _GL_INT_OP_WRAPV(a, b, r, op, builtin, overflow) builtin (a, b, r)
374
#elif 201112 <= __STDC_VERSION__ && !_GL__GENERIC_BOGUS
387
#elif 201112 <= __STDC_VERSION__ && !_GL__GENERIC_BOGUS
375
# define _GL_INT_OP_WRAPV(a, b, r, op, builtin, overflow) \
388
# define _GL_INT_OP_WRAPV(a, b, r, op, builtin, overflow) \
Lines 412-418 verify (TYPE_MAXIMUM (long long int) == Link Here
412
# else
425
# else
413
#  define _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow) \
426
#  define _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow) \
414
    _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \
427
    _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \
415
                     long int, LONG_MIN, LONG_MAX))
428
                     long int, LONG_MIN, LONG_MAX)
416
# endif
429
# endif
417
#endif
430
#endif
418
431
(-)diffutils-3.5/lib/xalloc-oversized.h.than (-32 / +21 lines)
Lines 1-6 Link Here
1
/* xalloc-oversized.h -- memory allocation size checking
1
/* xalloc-oversized.h -- memory allocation size checking
2
2
3
   Copyright (C) 1990-2000, 2003-2004, 2006-2016 Free Software Foundation, Inc.
3
   Copyright (C) 1990-2000, 2003-2004, 2006-2017 Free Software Foundation, Inc.
4
4
5
   This program is free software: you can redistribute it and/or modify
5
   This program is free software: you can redistribute it and/or modify
6
   it under the terms of the GNU General Public License as published by
6
   it under the terms of the GNU General Public License as published by
Lines 19-66 Link Here
19
#define XALLOC_OVERSIZED_H_
19
#define XALLOC_OVERSIZED_H_
20
20
21
#include <stddef.h>
21
#include <stddef.h>
22
#include <stdint.h>
22
23
23
/* Default for (non-Clang) compilers that lack __has_builtin.  */
24
/* True if N * S would overflow in a size_t calculation,
24
#ifndef __has_builtin
25
   or would generate a value larger than PTRDIFF_MAX.
25
# define __has_builtin(x) 0
26
#endif
27
28
/* True if N * S would overflow in a size calculation.
29
   This expands to a constant expression if N and S are both constants.
26
   This expands to a constant expression if N and S are both constants.
30
   By gnulib convention, SIZE_MAX represents overflow in size
27
   By gnulib convention, SIZE_MAX represents overflow in size
31
   calculations, so the conservative dividend to use here is
28
   calculations, so the conservative size_t-based dividend to use here
32
   SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value.
29
   is SIZE_MAX - 1.  */
33
   However, malloc (SIZE_MAX) fails on all known hosts where
34
   sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for
35
   exactly-SIZE_MAX allocations on such hosts; this avoids a test and
36
   branch when S is known to be 1.  */
37
#define __xalloc_oversized(n, s) \
30
#define __xalloc_oversized(n, s) \
38
    ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n))
31
  ((size_t) (PTRDIFF_MAX < SIZE_MAX ? PTRDIFF_MAX : SIZE_MAX - 1) / (s) < (n))
39
32
33
#if PTRDIFF_MAX < SIZE_MAX
34
typedef ptrdiff_t __xalloc_count_type;
35
#else
36
typedef size_t __xalloc_count_type;
37
#endif
40
38
41
/* Return 1 if an array of N objects, each of size S, cannot exist due
39
/* Return 1 if an array of N objects, each of size S, cannot exist
42
   to size arithmetic overflow.  S must be positive and N must be
40
   reliably due to size or ptrdiff_t arithmetic overflow.  S must be
43
   nonnegative.  This is a macro, not a function, so that it
41
   positive and N must be nonnegative.  This is a macro, not a
44
   works correctly even when SIZE_MAX < N.  */
42
   function, so that it works correctly even when SIZE_MAX < N.  */
45
43
46
/* GCC 7 __builtin_mul_overflow should easily compute this.  See:
47
   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68120  */
48
#if 7 <= __GNUC__
44
#if 7 <= __GNUC__
49
# define xalloc_oversized(n, s) __builtin_mul_overflow (n, s, (size_t *) NULL)
45
# define xalloc_oversized(n, s) \
50
46
   __builtin_mul_overflow_p (n, s, (__xalloc_count_type) 1)
51
/* GCC 5 and Clang __builtin_mul_overflow needs a temporary, and
47
#elif 5 <= __GNUC__ && !__STRICT_ANSI__
52
   should be used only for non-constant operands, so that
53
   xalloc_oversized is a constant expression if both arguments are.
54
   Do not use this if pedantic, since pedantic GCC issues a diagnostic
55
   for ({ ... }).  */
56
#elif ((5 <= __GNUC__ \
57
        || (__has_builtin (__builtin_mul_overflow) \
58
            && __has_builtin (__builtin_constant_p))) \
59
       && !__STRICT_ANSI__)
60
# define xalloc_oversized(n, s) \
48
# define xalloc_oversized(n, s) \
61
   (__builtin_constant_p (n) && __builtin_constant_p (s) \
49
   (__builtin_constant_p (n) && __builtin_constant_p (s) \
62
    ? __xalloc_oversized (n, s) \
50
    ? __xalloc_oversized (n, s) \
63
    : ({ size_t __xalloc_size; __builtin_mul_overflow (n, s, &__xalloc_size); }))
51
    : ({ __xalloc_count_type __xalloc_count; \
52
         __builtin_mul_overflow (n, s, &__xalloc_count); }))
64
53
65
/* Other compilers use integer division; this may be slower but is
54
/* Other compilers use integer division; this may be slower but is
66
   more portable.  */
55
   more portable.  */

Return to bug 617538