- /* 2 characters per byte printed in hex, +1 for '/' and +1 for '\0' */
- build_id_char_len = (2 * bin->build_id_len) + 1;
+ /*
+ * The prefix dir is the first byte of the build id, represented in
+ * lowercase hex as two characters per byte, +1 for '\0'.
+ */
+ build_id_prefix_dir = g_new0(gchar, BUILD_ID_PREFIX_DIR_LEN + 1);
+ if (!build_id_prefix_dir) {
+ goto error;
+ }
+ g_snprintf(build_id_prefix_dir, BUILD_ID_PREFIX_DIR_LEN + 1, "%02x", bin->build_id[0]);
+
+ /*
+ * The build id file is the remaining bytes of the build id,
+ * represented in lowercase hex, as two characters per byte.
+ */
+ build_id_char_len = (2 * (bin->build_id_len - 1));
+
+ /* To which the build id suffix is added, +1 for '\0'. */