From 5178871f033614cdf9e6623eb3dcba95f71d2e87 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Sun, 29 Jan 2012 20:17:31 +0400 Subject: [PATCH] Code refactoring of Darwin GC_dyld_image_add/remove (make read-only array 'const' and remove trailing NULL) * dyn_load.c (GC_dyld_add_sect_fmts): Add 'const' keyword to global array definition; remove trailing NULL. * dyn_load.c (GC_dyld_image_add, GC_dyld_image_remove): Test array index boundary instead of testing for trailing NULL. --- dyn_load.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dyn_load.c b/dyn_load.c index 31ec0537..fefb300a 100644 --- a/dyn_load.c +++ b/dyn_load.c @@ -1197,13 +1197,11 @@ STATIC const struct { /* containing private vs. public symbols. It also constructs */ /* sections specifically for zero-sized objects, when the */ /* target supports section anchors. */ -STATIC const char * GC_dyld_add_sect_fmts[] = -{ +STATIC const char * const GC_dyld_add_sect_fmts[] = { "__bss%u", "__pu_bss%u", "__zo_bss%u", - "__zo_pu_bss%u", - NULL + "__zo_pu_bss%u" }; /* Currently, mach-o will allow up to the max of 2^15 alignment */ @@ -1263,7 +1261,8 @@ STATIC void GC_dyld_image_add(const struct GC_MACH_HEADER *hdr, } /* Sections constructed on demand. */ - for (j = 0; (fmt = GC_dyld_add_sect_fmts[j]) != NULL; j++) { + for (j = 0; j < sizeof(GC_dyld_add_sect_fmts) / sizeof(char *); j++) { + fmt = GC_dyld_add_sect_fmts[j]; /* Add our manufactured aligned BSS sections. */ for (i = 0; i <= L2_MAX_OFILE_ALIGNMENT; i++) { snprintf(secnam, sizeof(secnam), fmt, (unsigned)i); @@ -1314,7 +1313,8 @@ STATIC void GC_dyld_image_remove(const struct GC_MACH_HEADER *hdr, } /* Remove our on-demand sections. */ - for (j = 0; (fmt = GC_dyld_add_sect_fmts[j]) != NULL; j++) { + for (j = 0; j < sizeof(GC_dyld_add_sect_fmts) / sizeof(char *); j++) { + fmt = GC_dyld_add_sect_fmts[j]; for (i = 0; i <= L2_MAX_OFILE_ALIGNMENT; i++) { snprintf(secnam, sizeof(secnam), fmt, (unsigned)i); sec = GC_GETSECTBYNAME(hdr, SEG_DATA, secnam); -- 2.49.0