]> granicus.if.org Git - gc/commitdiff
Code refactoring of Darwin GC_dyld_image_add/remove (make read-only
authorIvan Maidanski <ivmai@mail.ru>
Sun, 29 Jan 2012 16:17:31 +0000 (20:17 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Sun, 29 Jan 2012 16:17:31 +0000 (20:17 +0400)
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

index 31ec0537865e19f11ee763c7ef471f53d0942780..fefb300ae10ca1f81c5f5146940712bfeddbd0d1 100644 (file)
@@ -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);