[applied] elf-reader: Use -1 as a sentinel value for file descriptors
Commit Message
Hello,
In the code of abg-elf-reader.cc, the value 0 is used as a sentinel
value to signify that a given file descriptor is not set. Because
POSIX allows 0 as a normal file descriptor value, this patch uses -1
as a sentinel value.
* src/abg-elf-reader.cc (reader::priv::alt_{ctd,dwarf}_fd):
Initialize to -1 instead of 0.
(reader::priv::{initialize, clear_alt_dwarf_debug_info_data,
clear_alt_ctf_debug_info_data}): Likewise.
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
Applied to the mainline.
---
src/abg-elf-reader.cc | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
@@ -137,9 +137,9 @@ struct reader::priv
// and make the DWARF reference it in here.
Dwarf* alt_dwarf_handle = nullptr;
string alt_dwarf_path;
- int alt_dwarf_fd = 0;
+ int alt_dwarf_fd = -1;
Elf_Scn* ctf_section = nullptr;
- int alt_ctf_fd = 0;
+ int alt_ctf_fd = -1;
Elf* alt_ctf_handle = nullptr;
Elf_Scn* alt_ctf_section = nullptr;
Elf_Scn* btf_section = nullptr;
@@ -182,11 +182,11 @@ struct reader::priv
dwarf_handle = nullptr;
alt_dwarf_handle = nullptr;
alt_dwarf_path.clear();
- alt_dwarf_fd = 0;
+ alt_dwarf_fd = -1;
ctf_section = nullptr;
alt_ctf_section = nullptr;
alt_ctf_handle = nullptr;
- alt_ctf_fd = 0;
+ alt_ctf_fd = -1;
}
/// Initialize the debug info root path. The format of this path is
@@ -271,7 +271,7 @@ struct reader::priv
void
clear_alt_dwarf_debug_info_data()
{
- if (alt_dwarf_fd)
+ if (alt_dwarf_fd != -1)
{
if (alt_dwarf_handle)
{
@@ -279,7 +279,7 @@ struct reader::priv
alt_dwarf_handle = nullptr;
}
close(alt_dwarf_fd);
- alt_dwarf_fd = 0;
+ alt_dwarf_fd = -1;
}
alt_dwarf_path.clear();
}
@@ -305,10 +305,10 @@ struct reader::priv
void
clear_alt_ctf_debug_info_data()
{
- if (alt_ctf_fd)
+ if (alt_ctf_fd != -1)
{
close(alt_ctf_fd);
- alt_ctf_fd = 0;
+ alt_ctf_fd = -1;
}
if (alt_ctf_handle)
{