annotate lib/safe-alloc.h @ 40231:9b3c79fdfe0b

strtod: fix clash with strtold Problem reported for RHEL 5 by Jesse Caldwell (Bug#34817). * lib/strtod.c (compute_minus_zero, minus_zero): Simplify by remving the macro / external variable, and having just a function. User changed. This avoids the need for an external variable that might clash.
author Paul Eggert <eggert@cs.ucla.edu>
date Mon, 11 Mar 2019 16:40:29 -0700
parents b06060465f09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12023
e1d31e5feef2 Use the standard header with LGPL copyright.
Bruno Haible <bruno@clisp.org>
parents: 11253
diff changeset
1 /* safe-alloc.h: safer memory allocation
e1d31e5feef2 Use the standard header with LGPL copyright.
Bruno Haible <bruno@clisp.org>
parents: 11253
diff changeset
2
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
3 Copyright (C) 2009-2019 Free Software Foundation, Inc.
12023
e1d31e5feef2 Use the standard header with LGPL copyright.
Bruno Haible <bruno@clisp.org>
parents: 11253
diff changeset
4
e1d31e5feef2 Use the standard header with LGPL copyright.
Bruno Haible <bruno@clisp.org>
parents: 11253
diff changeset
5 This program is free software: you can redistribute it and/or modify it
12024
200a0145c440 Use the standard header with GPL copyright.
Bruno Haible <bruno@clisp.org>
parents: 12023
diff changeset
6 under the terms of the GNU General Public License as published by the
200a0145c440 Use the standard header with GPL copyright.
Bruno Haible <bruno@clisp.org>
parents: 12023
diff changeset
7 Free Software Foundation; either version 3 of the License, or any
200a0145c440 Use the standard header with GPL copyright.
Bruno Haible <bruno@clisp.org>
parents: 12023
diff changeset
8 later version.
12023
e1d31e5feef2 Use the standard header with LGPL copyright.
Bruno Haible <bruno@clisp.org>
parents: 11253
diff changeset
9
e1d31e5feef2 Use the standard header with LGPL copyright.
Bruno Haible <bruno@clisp.org>
parents: 11253
diff changeset
10 This program is distributed in the hope that it will be useful,
e1d31e5feef2 Use the standard header with LGPL copyright.
Bruno Haible <bruno@clisp.org>
parents: 11253
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12024
200a0145c440 Use the standard header with GPL copyright.
Bruno Haible <bruno@clisp.org>
parents: 12023
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
200a0145c440 Use the standard header with GPL copyright.
Bruno Haible <bruno@clisp.org>
parents: 12023
diff changeset
13 GNU General Public License for more details.
12023
e1d31e5feef2 Use the standard header with LGPL copyright.
Bruno Haible <bruno@clisp.org>
parents: 11253
diff changeset
14
12024
200a0145c440 Use the standard header with GPL copyright.
Bruno Haible <bruno@clisp.org>
parents: 12023
diff changeset
15 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
11173
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
17
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
18 /* Written by Daniel Berrange <berrange@redhat.com>, 2008 */
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
19
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
20 #ifndef SAFE_ALLOC_H_
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
21 # define SAFE_ALLOC_H_
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
22
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
23 # include <stdlib.h>
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
24
11253
c90f22b1783e Fix compilation error on non-glibc systems.
David Lutterkort <lutter@redhat.com>
parents: 11204
diff changeset
25 #ifndef __GNUC_PREREQ
c90f22b1783e Fix compilation error on non-glibc systems.
David Lutterkort <lutter@redhat.com>
parents: 11204
diff changeset
26 # if defined __GNUC__ && defined __GNUC_MINOR__
c90f22b1783e Fix compilation error on non-glibc systems.
David Lutterkort <lutter@redhat.com>
parents: 11204
diff changeset
27 # define __GNUC_PREREQ(maj, min) \
c90f22b1783e Fix compilation error on non-glibc systems.
David Lutterkort <lutter@redhat.com>
parents: 11204
diff changeset
28 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
c90f22b1783e Fix compilation error on non-glibc systems.
David Lutterkort <lutter@redhat.com>
parents: 11204
diff changeset
29 # else
c90f22b1783e Fix compilation error on non-glibc systems.
David Lutterkort <lutter@redhat.com>
parents: 11204
diff changeset
30 # define __GNUC_PREREQ(maj, min) 0
c90f22b1783e Fix compilation error on non-glibc systems.
David Lutterkort <lutter@redhat.com>
parents: 11204
diff changeset
31 # endif
c90f22b1783e Fix compilation error on non-glibc systems.
David Lutterkort <lutter@redhat.com>
parents: 11204
diff changeset
32 #endif
c90f22b1783e Fix compilation error on non-glibc systems.
David Lutterkort <lutter@redhat.com>
parents: 11204
diff changeset
33
14351
724011432f7b Consistent macro naming for macros that use GCC __attribute__.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
34 # ifndef _GL_ATTRIBUTE_RETURN_CHECK
11173
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
35 # if __GNUC_PREREQ (3, 4)
14351
724011432f7b Consistent macro naming for macros that use GCC __attribute__.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
36 # define _GL_ATTRIBUTE_RETURN_CHECK __attribute__((__warn_unused_result__))
11173
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
37 # else
14351
724011432f7b Consistent macro naming for macros that use GCC __attribute__.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
38 # define _GL_ATTRIBUTE_RETURN_CHECK
11173
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
39 # endif
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
40 # endif
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
41
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
42 /* Don't call these directly - use the macros below */
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
43 int
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
44 safe_alloc_alloc_n (void *ptrptr, size_t size, size_t count, int zeroed)
14351
724011432f7b Consistent macro naming for macros that use GCC __attribute__.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
45 _GL_ATTRIBUTE_RETURN_CHECK;
11173
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
46
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
47 int
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
48 safe_alloc_realloc_n (void *ptrptr, size_t size, size_t count)
14351
724011432f7b Consistent macro naming for macros that use GCC __attribute__.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
49 _GL_ATTRIBUTE_RETURN_CHECK;
11173
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
50
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
51 /**
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
52 * ALLOC:
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
53 * @ptr: pointer to hold address of allocated memory
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
54 *
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
55 * Allocate sizeof(*ptr) bytes of memory and store
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
56 * the address of allocated memory in 'ptr'. Fill the
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
57 * newly allocated memory with zeros.
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
58 *
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
59 * Return -1 on failure to allocate, zero on success
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
60 */
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
61 # define ALLOC(ptr) \
13051
094f6cfdb5c3 Minor formatting changes.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
62 safe_alloc_alloc_n (&(ptr), sizeof (*(ptr)), 1, 1)
11173
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
63
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
64 /**
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
65 * ALLOC_N:
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
66 * @ptr: pointer to hold address of allocated memory
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
67 * @count: number of elements to allocate
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
68 *
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
69 * Allocate an array of 'count' elements, each sizeof(*ptr)
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
70 * bytes long and store the address of allocated memory in
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
71 * 'ptr'. Fill the newly allocated memory with zeros.
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
72 *
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
73 * Return -1 on failure, 0 on success
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
74 */
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
75 # define ALLOC_N(ptr, count) \
13051
094f6cfdb5c3 Minor formatting changes.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
76 safe_alloc_alloc_n (&(ptr), sizeof (*(ptr)), (count), 1)
11173
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
77
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
78 /**
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
79 * ALLOC_N_UNINITIALIZED:
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
80 * @ptr: pointer to hold address of allocated memory
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
81 * @count: number of elements to allocate
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
82 *
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
83 * Allocate an array of 'count' elements, each sizeof(*ptr)
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
84 * bytes long and store the address of allocated memory in
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
85 * 'ptr'. Do not initialize the new memory at all.
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
86 *
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
87 * Return -1 on failure to allocate, zero on success
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
88 */
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
89 # define ALLOC_N_UNINITIALIZED(ptr, count) \
13051
094f6cfdb5c3 Minor formatting changes.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
90 safe_alloc_alloc_n (&(ptr), sizeof (*(ptr)), (count), 0)
11173
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
91
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
92 /**
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
93 * REALLOC_N:
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
94 * @ptr: pointer to hold address of allocated memory
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
95 * @count: number of elements to allocate
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
96 *
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
97 * Re-allocate an array of 'count' elements, each sizeof(*ptr)
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
98 * bytes long and store the address of allocated memory in
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
99 * 'ptr'. Fill the newly allocated memory with zeros
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
100 *
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
101 * Return -1 on failure to reallocate, zero on success
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
102 */
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
103 # define REALLOC_N(ptr, count) \
13051
094f6cfdb5c3 Minor formatting changes.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
104 safe_alloc_realloc_n (&(ptr), sizeof (*(ptr)), (count))
11173
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
105
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
106 /**
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
107 * FREE:
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
108 * @ptr: pointer holding address to be freed
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
109 *
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
110 * Free the memory stored in 'ptr' and update to point
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
111 * to NULL.
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
112 */
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
113 # define FREE(ptr) \
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
114 do \
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
115 { \
11204
55b4123a6159 Cosmetic tweaks in the safe-alloc module.
Bruno Haible <bruno@clisp.org>
parents: 11173
diff changeset
116 free (ptr); \
11173
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
117 (ptr) = NULL; \
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
118 } \
13051
094f6cfdb5c3 Minor formatting changes.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
119 while (0)
11173
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
120
af090b4101b4 New module 'safe-alloc'.
David Lutterkort <lutter@redhat.com>
parents:
diff changeset
121 #endif /* SAFE_ALLOC_H_ */