vapier      14/03/20 07:59:27

  Modified:             scanelf.c xfuncs.h
  Log:
  move array_cnt check into array_for_each init
  
  atm, if you try to use array_for_each or array_flatten_str on an array that 
has no members, you will get a segfault.  this is an easy rule to forget (and 
the current code does just that in at least one place), so move the array_cnt 
check into the init phase.  theres negligible code size impact so it should not 
be a big deal.

Revision  Changes    Path
1.261                pax-utils/scanelf.c

file : 
http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/scanelf.c?rev=1.261&view=markup
plain: 
http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/scanelf.c?rev=1.261&content-type=text/plain
diff : 
http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/scanelf.c?r1=1.260&r2=1.261

Index: scanelf.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v
retrieving revision 1.260
retrieving revision 1.261
diff -u -r1.260 -r1.261
--- scanelf.c   11 Jan 2014 00:28:49 -0000      1.260
+++ scanelf.c   20 Mar 2014 07:59:27 -0000      1.261
@@ -1,13 +1,13 @@
 /*
  * Copyright 2003-2012 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.260 
2014/01/11 00:28:49 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.261 
2014/03/20 07:59:27 vapier Exp $
  *
  * Copyright 2003-2012 Ned Ludd        - <so...@gentoo.org>
  * Copyright 2004-2012 Mike Frysinger  - <vap...@gentoo.org>
  */
 
-static const char rcsid[] = "$Id: scanelf.c,v 1.260 2014/01/11 00:28:49 vapier 
Exp $";
+static const char rcsid[] = "$Id: scanelf.c,v 1.261 2014/03/20 07:59:27 vapier 
Exp $";
 const char argv0[] = "scanelf";
 
 #include "paxinc.h"
@@ -1897,12 +1897,10 @@
        _load_ld_cache_config(fname);
 
        scan_l = scan_ul = scan_ull = false;
-       if (array_cnt(ldpaths)) {
-               array_for_each(ldpaths, n, ldpath) {
-                       if (!scan_l   && !strcmp(ldpath, "/lib"))           
scan_l   = true;
-                       if (!scan_ul  && !strcmp(ldpath, "/usr/lib"))       
scan_ul  = true;
-                       if (!scan_ull && !strcmp(ldpath, "/usr/local/lib")) 
scan_ull = true;
-               }
+       array_for_each(ldpaths, n, ldpath) {
+               if (!scan_l   && !strcmp(ldpath, "/lib"))           scan_l   = 
true;
+               if (!scan_ul  && !strcmp(ldpath, "/usr/lib"))       scan_ul  = 
true;
+               if (!scan_ull && !strcmp(ldpath, "/usr/local/lib")) scan_ull = 
true;
        }
 
        if (!scan_l)   xarraypush_str(ldpaths, "/lib");
@@ -2268,12 +2266,9 @@
                }
        }
        /* flatten arrays for display */
-       if (array_cnt(find_sym_arr))
-               find_sym = array_flatten_str(find_sym_arr);
-       if (array_cnt(find_lib_arr))
-               find_lib = array_flatten_str(find_lib_arr);
-       if (array_cnt(find_section_arr))
-               find_section = array_flatten_str(find_section_arr);
+       find_sym = array_flatten_str(find_sym_arr);
+       find_lib = array_flatten_str(find_lib_arr);
+       find_section = array_flatten_str(find_section_arr);
        /* let the format option override all other options */
        if (out_format) {
                show_pax = show_phdr = show_textrel = show_rpath = \



1.8                  pax-utils/xfuncs.h

file : 
http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/xfuncs.h?rev=1.8&view=markup
plain: 
http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/xfuncs.h?rev=1.8&content-type=text/plain
diff : 
http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/xfuncs.h?r1=1.7&r2=1.8

Index: xfuncs.h
===================================================================
RCS file: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- xfuncs.h    4 Nov 2012 07:26:24 -0000       1.7
+++ xfuncs.h    20 Mar 2014 07:59:27 -0000      1.8
@@ -1,7 +1,7 @@
 /*
  * Copyright 2003-2012 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.h,v 1.7 2012/11/04 
07:26:24 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.h,v 1.8 2014/03/20 
07:59:27 vapier Exp $
  *
  * Copyright 2003-2012 Ned Ludd        - <so...@gentoo.org>
  * Copyright 2004-2012 Mike Frysinger  - <vap...@gentoo.org>
@@ -29,7 +29,9 @@
 void xarrayfree(array_t *array);
 #define xrealloc_array(ptr, size, ele_size) xrealloc(ptr, (size) * (ele_size))
 #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])
 #define array_init_decl { .eles = NULL, .num = 0, }
 #define array_cnt(arr) (arr)->num
 char *array_flatten_str(array_t *array);




Reply via email to