Always use our own MAX/MIN definitions

code in src/shared/macro.h only defined MAX/MIN in case
they were not defined previously. however the MAX/MIN
macros implemented in glibc are not of the "safe" kind but defined
as:

define MIN(a,b) (((a)<(b))?(a):(b))
define MAX(a,b) (((a)>(b))?(a):(b))

Avoid nasty side effects by using our own versions instead.

Also fix the warnings derived from this change.

[zj: - modify MAX3 macro to fix warning about _a shadowing _a,
     - do bootchart/svg.c too,
     - remove unused MIN3.]
This commit is contained in:
Cristian Rodríguez
2013-04-01 23:43:48 -04:00
committed by Zbigniew Jędrzejewski-Szmek
parent e5ec62c569
commit 9607d9470e
7 changed files with 30 additions and 35 deletions
+12 -14
View File
@@ -71,29 +71,27 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) {
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#ifndef MAX
#define MAX(a,b) \
__extension__ ({ \
typeof(a) _a = (a); \
typeof(b) _b = (b); \
_a > _b ? _a : _b; \
#undef MAX
#define MAX(a,b) \
__extension__ ({ \
typeof(a) _a = (a); \
typeof(b) _b = (b); \
_a > _b ? _a : _b; \
})
#endif
#define MAX3(a,b,c) \
MAX(MAX(a,b),c)
#define MAX3(x,y,z) \
__extension__ ({ \
typeof(x) _c = MAX(x,y); \
MAX(_c, z); \
})
#ifndef MIN
#undef MIN
#define MIN(a,b) \
__extension__ ({ \
typeof(a) _a = (a); \
typeof(b) _b = (b); \
_a < _b ? _a : _b; \
})
#endif
#define MIN3(a,b,c) \
MIN(MIN(a,b),c)
#ifndef CLAMP
#define CLAMP(x, low, high) \
+1 -1
View File
@@ -159,7 +159,7 @@ int prioq_put(Prioq *q, void *data, unsigned *idx) {
unsigned n;
struct prioq_item *j;
n = MAX((q->n_items+1) * 2, 16);
n = MAX((q->n_items+1) * 2, 16u);
j = realloc(q->items, sizeof(struct prioq_item) * n);
if (!j)
return -ENOMEM;
+1 -1
View File
@@ -5862,7 +5862,7 @@ void* greedy_realloc(void **p, size_t *allocated, size_t need) {
if (*allocated >= need)
return *p;
a = MAX(64, need * 2);
a = MAX(64u, need * 2);
q = realloc(*p, a);
if (!q)
return NULL;