diff options
author | Lorenz <12514511+RincewindsHat@users.noreply.github.com> | 2023-03-27 10:34:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-27 10:34:19 (GMT) |
commit | bbc97d57f7f9e0a49fea78c02861c444fe95d46a (patch) | |
tree | c8956bbbe9b73e37d261735699a82cccaacea0db /gl/xsize.h | |
parent | 917dba07fded8ef04967183a4c0443b5cce2db82 (diff) | |
parent | 482aa6c7fe86d7a899e4888d14149f1ccd5401fd (diff) | |
download | monitoring-plugins-bbc97d5.tar.gz |
Merge branch 'master' into dev/check_ssh-patches
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: |