~ubuntu-branches/ubuntu/trusty/grub2/trusty

« back to all changes in this revision

Viewing changes to grub-core/gnulib/xsize.h

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2014-01-16 15:18:04 UTC
  • mfrom: (17.6.38 experimental)
  • Revision ID: package-import@ubuntu.com-20140116151804-3foouk7fpqcq3sxx
Tags: 2.02~beta2-2
* Convert patch handling to git-dpm.
* Add bi-endian support to ELF parser (Tomohiro B Berry).
* Adjust restore_mkdevicemap.patch to mark get_kfreebsd_version as static,
  to appease "gcc -Werror=missing-prototypes".
* Cherry-pick from upstream:
  - Change grub-macbless' manual page section to 8.
* Install grub-glue-efi, grub-macbless, grub-render-label, and
  grub-syslinux2cfg.
* grub-shell: Pass -no-pad to xorriso when building floppy images.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* xsize.h -- Checked size_t computations.
2
2
 
3
 
   Copyright (C) 2003, 2008, 2009, 2010 Free Software Foundation, Inc.
 
3
   Copyright (C) 2003, 2008-2013 Free Software Foundation, Inc.
4
4
 
5
5
   This program is free software; you can redistribute it and/or modify
6
6
   it under the terms of the GNU General Public License as published by
13
13
   GNU General Public License for more details.
14
14
 
15
15
   You should have received a copy of the GNU General Public License
16
 
   along with this program; if not, write to the Free Software Foundation,
17
 
   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
16
   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
18
17
 
19
18
#ifndef _XSIZE_H
20
19
#define _XSIZE_H
28
27
# include <stdint.h>
29
28
#endif
30
29
 
 
30
_GL_INLINE_HEADER_BEGIN
 
31
#ifndef XSIZE_INLINE
 
32
# define XSIZE_INLINE _GL_INLINE
 
33
#endif
 
34
 
31
35
/* The size of memory objects is often computed through expressions of
32
36
   type size_t. Example:
33
37
      void* p = malloc (header_size + n * element_size).
49
53
  ((N) <= SIZE_MAX ? (size_t) (N) : SIZE_MAX)
50
54
 
51
55
/* Sum of two sizes, with overflow check.  */
52
 
static inline size_t
 
56
XSIZE_INLINE size_t
53
57
#if __GNUC__ >= 3
54
58
__attribute__ ((__pure__))
55
59
#endif
60
64
}
61
65
 
62
66
/* Sum of three sizes, with overflow check.  */
63
 
static inline size_t
 
67
XSIZE_INLINE size_t
64
68
#if __GNUC__ >= 3
65
69
__attribute__ ((__pure__))
66
70
#endif
70
74
}
71
75
 
72
76
/* Sum of four sizes, with overflow check.  */
73
 
static inline size_t
 
77
XSIZE_INLINE size_t
74
78
#if __GNUC__ >= 3
75
79
__attribute__ ((__pure__))
76
80
#endif
80
84
}
81
85
 
82
86
/* Maximum of two sizes, with overflow check.  */
83
 
static inline size_t
 
87
XSIZE_INLINE size_t
84
88
#if __GNUC__ >= 3
85
89
__attribute__ ((__pure__))
86
90
#endif
93
97
 
94
98
/* Multiplication of a count with an element size, with overflow check.
95
99
   The count must be >= 0 and the element size must be > 0.
96
 
   This is a macro, not an inline function, so that it works correctly even
 
100
   This is a macro, not a function, so that it works correctly even
97
101
   when N is of a wider type and N > SIZE_MAX.  */
98
102
#define xtimes(N, ELSIZE) \
99
103
  ((N) <= SIZE_MAX / (ELSIZE) ? (size_t) (N) * (ELSIZE) : SIZE_MAX)
105
109
#define size_in_bounds_p(SIZE) \
106
110
  ((SIZE) != SIZE_MAX)
107
111
 
 
112
_GL_INLINE_HEADER_END
 
113
 
108
114
#endif /* _XSIZE_H */