MCPcopy Create free account
hub / github.com/eggert/tz / sumsize

Function sumsize

zdump.c:126–139  ·  view source on GitHub ↗

Return A + B, exiting if the result would overflow either ptrdiff_t or size_t. A and B are both nonnegative. */

Source from the content-addressed store, hash-verified

124/* Return A + B, exiting if the result would overflow either ptrdiff_t
125 or size_t. A and B are both nonnegative. */
126ATTRIBUTE_PURE_114833_HACK
127static ptrdiff_t
128sumsize(ptrdiff_t a, ptrdiff_t b)
129{
130#ifdef ckd_add
131 ptrdiff_t sum;
132 if (!ckd_add(&sum, a, b) && sum <= INDEX_MAX)
133 return sum;
134#else
135 if (a <= INDEX_MAX && b <= INDEX_MAX - a)
136 return a + b;
137#endif
138 size_overflow();
139}
140
141
142/* Return a pointer to a newly allocated buffer of size SIZE, exiting

Callers 4

tzallocFunction · 0.85
saveabbrFunction · 0.85
istrftimeFunction · 0.85
showtransFunction · 0.85

Calls 1

size_overflowFunction · 0.70

Tested by

no test coverage detected