From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 2A3061384B4 for ; Thu, 26 Nov 2015 08:43:50 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 9840121C020; Thu, 26 Nov 2015 08:43:49 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 391CC21C020 for ; Thu, 26 Nov 2015 08:43:49 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 50D13340139 for ; Thu, 26 Nov 2015 08:43:48 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 2A24F99D for ; Thu, 26 Nov 2015 08:43:47 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1448526945.66090491b033778785f12ccd3f20cdf54e89c87a.vapier@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/ X-VCS-Repository: proj/portage-utils X-VCS-Files: libq/xarray.c X-VCS-Directories: libq/ X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: 66090491b033778785f12ccd3f20cdf54e89c87a X-VCS-Branch: master Date: Thu, 26 Nov 2015 08:43:47 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 931b2830-026e-4af7-9cc0-020b217a1a5e X-Archives-Hash: 5867a1411a2d7f9a2a4a0e86b5beb33f commit: 66090491b033778785f12ccd3f20cdf54e89c87a Author: Mike Frysinger gentoo org> AuthorDate: Thu Nov 26 08:35:45 2015 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Thu Nov 26 08:35:45 2015 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=66090491 xarray: sync logic with latest pax-utils This pulls in two fixes: - handling of empty arrays - invalid loads at end of arrays URL: https://bugs.gentoo.org/553368 Reported-by: Hanno Boeck gentoo.org> libq/xarray.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libq/xarray.c b/libq/xarray.c index b4c3857..56f04da 100644 --- a/libq/xarray.c +++ b/libq/xarray.c @@ -12,8 +12,14 @@ typedef struct { } array_t; #define xrealloc_array(ptr, size, ele_size) xrealloc(ptr, (size) * (ele_size)) +/* The assignment after the check is unfortunate as we do a non-NULL check (we + * already do not permit pushing of NULL pointers), but we can't put it in the + * increment phase as that will cause a load beyond the bounds of valid memory. + */ #define array_for_each(arr, n, ele) \ - for (n = 0, ele = arr->eles[n]; n < arr->num; ++n, ele = arr->eles[n]) + for (n = 0, ele = array_cnt(arr) ? arr->eles[n] : NULL; \ + n < array_cnt(arr) && (ele = arr->eles[n]); \ + ++n) #define array_init_decl { .eles = NULL, .num = 0, } #define array_cnt(arr) (arr)->num #define DECLARE_ARRAY(arr) array_t _##arr = array_init_decl, *arr = &_##arr