From 3f1c2c382788f0718f13a3e9ab51f0c64c5b67da Mon Sep 17 00:00:00 2001 From: Wesley Shillingford Date: Sat, 13 Jul 2019 14:55:58 +0100 Subject: [PATCH] Fix unused variable error in deployments (#2147) * Fix unused variable error in deployments * Remove Name: from files output --- nano/lib/plat/linux/debugging.cpp | 40 ++++++++++++++++++------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/nano/lib/plat/linux/debugging.cpp b/nano/lib/plat/linux/debugging.cpp index 2cfeb4e1..41b06863 100644 --- a/nano/lib/plat/linux/debugging.cpp +++ b/nano/lib/plat/linux/debugging.cpp @@ -27,28 +27,34 @@ int create_load_memory_address_file (dl_phdr_info * info, size_t, void *) 0 #endif ); - - // Write the name of shared library - ::write (file_descriptor, "Name: ", 6); - ::write (file_descriptor, info->dlpi_name, strlen (info->dlpi_name)); - ::write (file_descriptor, "\n", 1); - - // Write the first load address found - for (auto i = 0; i < info->dlpi_phnum; ++i) + assert (file_descriptor); + if (file_descriptor) { - if (info->dlpi_phdr[i].p_type == PT_LOAD) + // Write the name of shared library (can be empty for the executable) + auto name_length = strlen (info->dlpi_name); + if (name_length == 0 || (::write (file_descriptor, info->dlpi_name, name_length) > 0 && ::write (file_descriptor, "\n", 1) > 0)) { - auto load_address = info->dlpi_addr + info->dlpi_phdr[i].p_vaddr; + // Write the first load address found + for (auto i = 0; i < info->dlpi_phnum; ++i) + { + if (info->dlpi_phdr[i].p_type == PT_LOAD) + { + auto load_address = info->dlpi_addr + info->dlpi_phdr[i].p_vaddr; - // Each byte of the pointer is two hexadecimal characters, plus the 0x prefix and null terminator - char load_address_as_hex_str[sizeof (load_address) * 2 + 2 + 1]; - snprintf (load_address_as_hex_str, sizeof (load_address_as_hex_str), "%p", (void *)load_address); - ::write (file_descriptor, load_address_as_hex_str, strlen (load_address_as_hex_str)); - break; + // Each byte of the pointer is two hexadecimal characters, plus the 0x prefix and null terminator + char load_address_as_hex_str[sizeof (load_address) * 2 + 2 + 1]; + snprintf (load_address_as_hex_str, sizeof (load_address_as_hex_str), "%p", (void *)load_address); + if (::write (file_descriptor, load_address_as_hex_str, strlen (load_address_as_hex_str)) > 0) + { + // Intentionally empty to satisfy compiler that the return value of write is used + } + break; + } + } } - } - ::close (file_descriptor); + ::close (file_descriptor); + } ++counter; return 0; }