)]}'
{
  "commit": "3f8f380190a6856e87237ec7c6a179399fe43d4d",
  "tree": "b12639ce972276140fba8a98f563891c1e035dc3",
  "parents": [
    "434a7a6bc895774968f68fbe7913d3a753d74b37"
  ],
  "author": {
    "name": "Matthieu Longo",
    "email": "matthieu.longo@arm.com",
    "time": "Fri Jan 24 15:19:36 2025 +0000"
  },
  "committer": {
    "name": "Matthieu Longo",
    "email": "matthieu.longo@arm.com",
    "time": "Tue Mar 04 11:02:03 2025 +0000"
  },
  "message": "clean-up readelf: simplify and flatten body of process_attributes\n\n- use find_section_by_type() instead of a for-loop.\n- reindent the whole function accordingly.\n- move declaration of variables nearer from their usage.\n- prune else branch by using a goto in the error case.\n\ndiff --git a/binutils/readelf.c b/binutils/readelf.c\nindex 6d3ec65a8a1..878012da8f0 100644\n--- a/binutils/readelf.c\n+++ b/binutils/readelf.c\n@@ -19268,42 +19268,32 @@ process_attributes (Filedata * filedata,\n                    unsigned char * (* display_pub_attribute) (unsigned char *, const unsigned char * const),\n                    unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const))\n {\n-  Elf_Internal_Shdr * sect;\n-  unsigned i;\n-  bool res \u003d true;\n-\n   /* Find the section header so that we get the size.  */\n-  for (i \u003d 0, sect \u003d filedata-\u003esection_headers;\n-       i \u003c filedata-\u003efile_header.e_shnum;\n-       i++, sect++)\n-    {\n-      unsigned char * contents;\n-      unsigned char * p;\n+  Elf_Internal_Shdr * sect \u003d find_section_by_type (filedata, proc_type);\n+  if (sect \u003d\u003d NULL)\n+    sect \u003d find_section_by_type (filedata, SHT_GNU_ATTRIBUTES);\n\n-      if (sect-\u003esh_type !\u003d proc_type \u0026\u0026 sect-\u003esh_type !\u003d SHT_GNU_ATTRIBUTES)\n-       continue;\n+  if (sect \u003d\u003d NULL)\n+    /* No section, exit without error.  */\n+    return true;\n\n-      contents \u003d (unsigned char *) get_data (NULL, filedata, sect-\u003esh_offset, 1,\n-                                             sect-\u003esh_size, _(\"attributes\"));\n+  unsigned char * contents \u003d (unsigned char *)\n+    get_data (NULL, filedata, sect-\u003esh_offset, 1, sect-\u003esh_size, _(\"attributes\"));\n   if (contents \u003d\u003d NULL)\n-       {\n-         res \u003d false;\n-         continue;\n-       }\n+    return false;\n\n-      p \u003d contents;\n+  bool res \u003d true;\n+  unsigned char * p \u003d contents;\n   /* The first character is the version of the attributes.\n      Currently only version 1, (aka \u0027A\u0027) is recognised here.  */\n   if (*p !\u003d \u0027A\u0027)\n     {\n       printf (_(\"Unknown attributes version \u0027%c\u0027(%d) - expecting \u0027A\u0027\\n\"), *p, *p);\n       res \u003d false;\n+      goto free_data;\n     }\n-      else\n-       {\n-         uint64_t section_len;\n\n-         section_len \u003d sect-\u003esh_size - 1;\n+  uint64_t section_len \u003d sect-\u003esh_size - 1;\n   p++;\n\n   while (section_len \u003e 0)\n@@ -19456,10 +19446,9 @@ process_attributes (Filedata * filedata,\n            attr_len \u003d 0;\n        }\n     }\n-       }\n\n+free_data:\n   free (contents);\n-    }\n\n   return res;\n }\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "56d66143eebc6c6ac731e4b099396726f609e335",
      "old_mode": 33188,
      "old_path": "binutils/readelf.c",
      "new_id": "dd1871d8c75a72bd0ea1ad2b5e5a3bbfd987ef98",
      "new_mode": 33188,
      "new_path": "binutils/readelf.c"
    }
  ]
}
