Gentoo Archives: gentoo-commits

From: Mike Frysinger <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/
Date: Thu, 26 Nov 2015 08:43:50
Message-Id: 1448526945.66090491b033778785f12ccd3f20cdf54e89c87a.vapier@gentoo
1 commit: 66090491b033778785f12ccd3f20cdf54e89c87a
2 Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
3 AuthorDate: Thu Nov 26 08:35:45 2015 +0000
4 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
5 CommitDate: Thu Nov 26 08:35:45 2015 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=66090491
7
8 xarray: sync logic with latest pax-utils
9
10 This pulls in two fixes:
11 - handling of empty arrays
12 - invalid loads at end of arrays
13
14 URL: https://bugs.gentoo.org/553368
15 Reported-by: Hanno Boeck <hanno <AT> gentoo.org>
16
17 libq/xarray.c | 8 +++++++-
18 1 file changed, 7 insertions(+), 1 deletion(-)
19
20 diff --git a/libq/xarray.c b/libq/xarray.c
21 index b4c3857..56f04da 100644
22 --- a/libq/xarray.c
23 +++ b/libq/xarray.c
24 @@ -12,8 +12,14 @@ typedef struct {
25 } array_t;
26
27 #define xrealloc_array(ptr, size, ele_size) xrealloc(ptr, (size) * (ele_size))
28 +/* The assignment after the check is unfortunate as we do a non-NULL check (we
29 + * already do not permit pushing of NULL pointers), but we can't put it in the
30 + * increment phase as that will cause a load beyond the bounds of valid memory.
31 + */
32 #define array_for_each(arr, n, ele) \
33 - for (n = 0, ele = arr->eles[n]; n < arr->num; ++n, ele = arr->eles[n])
34 + for (n = 0, ele = array_cnt(arr) ? arr->eles[n] : NULL; \
35 + n < array_cnt(arr) && (ele = arr->eles[n]); \
36 + ++n)
37 #define array_init_decl { .eles = NULL, .num = 0, }
38 #define array_cnt(arr) (arr)->num
39 #define DECLARE_ARRAY(arr) array_t _##arr = array_init_decl, *arr = &_##arr