diff options
author | Lorenz <12514511+RincewindsHat@users.noreply.github.com> | 2023-02-10 10:43:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-10 10:43:20 (GMT) |
commit | c07206f2ccc2356aa74bc6813a94c2190017d44e (patch) | |
tree | 1677e5fdca5c3ce544e92c5484e16a0b68df1cc9 /gl/xsize.h | |
parent | e92046f810658016b7c373677efefda3b21400e4 (diff) | |
parent | d2fcf49ad4afc15f37d082d7bc96a808369ec2d4 (diff) | |
download | monitoring-plugins-c07206f.tar.gz |
Merge pull request #1832 from RincewindsHat/gnulib_update_2023
Gnulib update 2023 and attendant fixes
Diffstat (limited to 'gl/xsize.h')
-rw-r--r-- | gl/xsize.h | 44 |
1 files changed, 19 insertions, 25 deletions
@@ -1,19 +1,19 @@ | |||
1 | /* xsize.h -- Checked size_t computations. | 1 | /* xsize.h -- Checked size_t computations. |
2 | 2 | ||
3 | Copyright (C) 2003, 2008-2013 Free Software Foundation, Inc. | 3 | Copyright (C) 2003, 2008-2023 Free Software Foundation, Inc. |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This file 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 Lesser General Public License as |
7 | the Free Software Foundation; either version 3, or (at your option) | 7 | published by the Free Software Foundation; either version 2.1 of the |
8 | any later version. | 8 | License, or (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This file is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU Lesser General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU Lesser General Public License |
16 | along with this program; if not, see <http://www.gnu.org/licenses/>. */ | 16 | along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
17 | 17 | ||
18 | #ifndef _XSIZE_H | 18 | #ifndef _XSIZE_H |
19 | #define _XSIZE_H | 19 | #define _XSIZE_H |
@@ -27,6 +27,12 @@ | |||
27 | # include <stdint.h> | 27 | # include <stdint.h> |
28 | #endif | 28 | #endif |
29 | 29 | ||
30 | /* Get ATTRIBUTE_PURE. */ | ||
31 | #include "attribute.h" | ||
32 | |||
33 | #ifndef _GL_INLINE_HEADER_BEGIN | ||
34 | #error "Please include config.h first." | ||
35 | #endif | ||
30 | _GL_INLINE_HEADER_BEGIN | 36 | _GL_INLINE_HEADER_BEGIN |
31 | #ifndef XSIZE_INLINE | 37 | #ifndef XSIZE_INLINE |
32 | # define XSIZE_INLINE _GL_INLINE | 38 | # define XSIZE_INLINE _GL_INLINE |
@@ -53,10 +59,7 @@ _GL_INLINE_HEADER_BEGIN | |||
53 | ((N) <= SIZE_MAX ? (size_t) (N) : SIZE_MAX) | 59 | ((N) <= SIZE_MAX ? (size_t) (N) : SIZE_MAX) |
54 | 60 | ||
55 | /* Sum of two sizes, with overflow check. */ | 61 | /* Sum of two sizes, with overflow check. */ |
56 | XSIZE_INLINE size_t | 62 | XSIZE_INLINE size_t ATTRIBUTE_PURE |
57 | #if __GNUC__ >= 3 | ||
58 | __attribute__ ((__pure__)) | ||
59 | #endif | ||
60 | xsum (size_t size1, size_t size2) | 63 | xsum (size_t size1, size_t size2) |
61 | { | 64 | { |
62 | size_t sum = size1 + size2; | 65 | size_t sum = size1 + size2; |
@@ -64,30 +67,21 @@ xsum (size_t size1, size_t size2) | |||
64 | } | 67 | } |
65 | 68 | ||
66 | /* Sum of three sizes, with overflow check. */ | 69 | /* Sum of three sizes, with overflow check. */ |
67 | XSIZE_INLINE size_t | 70 | XSIZE_INLINE size_t ATTRIBUTE_PURE |
68 | #if __GNUC__ >= 3 | ||
69 | __attribute__ ((__pure__)) | ||
70 | #endif | ||
71 | xsum3 (size_t size1, size_t size2, size_t size3) | 71 | xsum3 (size_t size1, size_t size2, size_t size3) |
72 | { | 72 | { |
73 | return xsum (xsum (size1, size2), size3); | 73 | return xsum (xsum (size1, size2), size3); |
74 | } | 74 | } |
75 | 75 | ||
76 | /* Sum of four sizes, with overflow check. */ | 76 | /* Sum of four sizes, with overflow check. */ |
77 | XSIZE_INLINE size_t | 77 | XSIZE_INLINE size_t ATTRIBUTE_PURE |
78 | #if __GNUC__ >= 3 | ||
79 | __attribute__ ((__pure__)) | ||
80 | #endif | ||
81 | xsum4 (size_t size1, size_t size2, size_t size3, size_t size4) | 78 | xsum4 (size_t size1, size_t size2, size_t size3, size_t size4) |
82 | { | 79 | { |
83 | return xsum (xsum (xsum (size1, size2), size3), size4); | 80 | return xsum (xsum (xsum (size1, size2), size3), size4); |
84 | } | 81 | } |
85 | 82 | ||
86 | /* Maximum of two sizes, with overflow check. */ | 83 | /* Maximum of two sizes, with overflow check. */ |
87 | XSIZE_INLINE size_t | 84 | XSIZE_INLINE size_t ATTRIBUTE_PURE |
88 | #if __GNUC__ >= 3 | ||
89 | __attribute__ ((__pure__)) | ||
90 | #endif | ||
91 | xmax (size_t size1, size_t size2) | 85 | xmax (size_t size1, size_t size2) |
92 | { | 86 | { |
93 | /* No explicit check is needed here, because for any n: | 87 | /* No explicit check is needed here, because for any n: |