summaryrefslogtreecommitdiffstats
path: root/gl/xsize.h
diff options
context:
space:
mode:
Diffstat (limited to 'gl/xsize.h')
-rw-r--r--gl/xsize.h44
1 files changed, 19 insertions, 25 deletions
diff --git a/gl/xsize.h b/gl/xsize.h
index 2922f35..1ec78e7 100644
--- a/gl/xsize.h
+++ b/gl/xsize.h
@@ -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. */
56XSIZE_INLINE size_t 62XSIZE_INLINE size_t ATTRIBUTE_PURE
57#if __GNUC__ >= 3
58__attribute__ ((__pure__))
59#endif
60xsum (size_t size1, size_t size2) 63xsum (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. */
67XSIZE_INLINE size_t 70XSIZE_INLINE size_t ATTRIBUTE_PURE
68#if __GNUC__ >= 3
69__attribute__ ((__pure__))
70#endif
71xsum3 (size_t size1, size_t size2, size_t size3) 71xsum3 (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. */
77XSIZE_INLINE size_t 77XSIZE_INLINE size_t ATTRIBUTE_PURE
78#if __GNUC__ >= 3
79__attribute__ ((__pure__))
80#endif
81xsum4 (size_t size1, size_t size2, size_t size3, size_t size4) 78xsum4 (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. */
87XSIZE_INLINE size_t 84XSIZE_INLINE size_t ATTRIBUTE_PURE
88#if __GNUC__ >= 3
89__attribute__ ((__pure__))
90#endif
91xmax (size_t size1, size_t size2) 85xmax (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: