From: Roland McGrath Date: Thu, 11 Jan 2007 05:06:16 +0000 (+0000) Subject: 2007-01-10 Roland McGrath X-Git-Tag: elfutils-0.126~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=44865b9e1e73f6c0e35c7d62a72cc73b513f65f0;p=thirdparty%2Felfutils.git 2007-01-10 Roland McGrath * linux-kernel-modules.c (report_kernel): Check asprintf return value directly instead of via side effect, to silence warn_unused_result. (dwfl_linux_kernel_report_offline): Likewise. (dwfl_linux_kernel_find_elf): Likewise. (dwfl_linux_kernel_module_section_address): Likewise. * find-debuginfo.c (try_open): Likewise. --- diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index e14cce9cf..67ecfe7d6 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,5 +1,12 @@ 2007-01-10 Roland McGrath + * linux-kernel-modules.c (report_kernel): Check asprintf return value + directly instead of via side effect, to silence warn_unused_result. + (dwfl_linux_kernel_report_offline): Likewise. + (dwfl_linux_kernel_find_elf): Likewise. + (dwfl_linux_kernel_module_section_address): Likewise. + * find-debuginfo.c (try_open): Likewise. + * libdwfl.h (dwfl_begin): Require nonnull argument. 2006-12-27 Roland McGrath diff --git a/libdwfl/find-debuginfo.c b/libdwfl/find-debuginfo.c index a99fd1441..ca1fadcb1 100644 --- a/libdwfl/find-debuginfo.c +++ b/libdwfl/find-debuginfo.c @@ -1,5 +1,5 @@ /* Standard find_debuginfo callback for libdwfl. - Copyright (C) 2005, 2006 Red Hat, Inc. + Copyright (C) 2005, 2006, 2007 Red Hat, Inc. This file is part of Red Hat elfutils. Red Hat elfutils is free software; you can redistribute it and/or modify @@ -60,17 +60,16 @@ static int try_open (const char *dir, const char *subdir, const char *debuglink, char **debuginfo_file_name) { - char *fname = NULL; + char *fname; if (dir == NULL && subdir == NULL) - fname = strdup (debuglink); - else if (subdir == NULL) - asprintf (&fname, "%s/%s", dir, debuglink); - else if (dir == NULL) - asprintf (&fname, "%s/%s", subdir, debuglink); - else - asprintf (&fname, "%s/%s/%s", dir, subdir, debuglink); - - if (fname == NULL) + { + fname = strdup (debuglink); + if (fname == NULL) + return -1; + } + else if ((subdir == NULL ? asprintf (&fname, "%s/%s", dir, debuglink) + : dir == NULL ? asprintf (&fname, "%s/%s", subdir, debuglink) + : asprintf (&fname, "%s/%s/%s", dir, subdir, debuglink)) < 0) return -1; int fd = TEMP_FAILURE_RETRY (open64 (fname, O_RDONLY)); diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c index 4d4194a5d..a39863866 100644 --- a/libdwfl/linux-kernel-modules.c +++ b/libdwfl/linux-kernel-modules.c @@ -1,5 +1,5 @@ /* Standard libdwfl callbacks for debugging the running Linux kernel. - Copyright (C) 2005, 2006 Red Hat, Inc. + Copyright (C) 2005, 2006, 2007 Red Hat, Inc. This file is part of Red Hat elfutils. Red Hat elfutils is free software; you can redistribute it and/or modify @@ -122,17 +122,17 @@ report_kernel (Dwfl *dwfl, const char *release, if (dwfl == NULL) return -1; - char *fname = NULL; - if (release[0] == '/') - asprintf (&fname, "%s/vmlinux", release); - else - asprintf (&fname, "/boot/vmlinux-%s", release); + char *fname; + if ((release[0] == '/' + ? asprintf (&fname, "%s/vmlinux", release) + : asprintf (&fname, "/boot/vmlinux-%s", release)) < 0) + return -1; int fd = try_kernel_name (dwfl, &fname); if (fd < 0 && release[0] != '/') { free (fname); - fname = NULL; - asprintf (&fname, MODULEDIRFMT "/vmlinux", release); + if (asprintf (&fname, MODULEDIRFMT "/vmlinux", release) < 0) + return -1; fd = try_kernel_name (dwfl, &fname); } @@ -195,8 +195,7 @@ dwfl_linux_kernel_report_offline (Dwfl *dwfl, const char *release, modulesdir[0] = (char *) release; else { - asprintf (&modulesdir[0], MODULEDIRFMT "/kernel", release); - if (modulesdir[0] == NULL) + if (asprintf (&modulesdir[0], MODULEDIRFMT "/kernel", release) < 0) return errno; } @@ -310,8 +309,7 @@ dwfl_linux_kernel_find_elf (Dwfl_Module *mod __attribute__ ((unused)), /* Do "find /lib/modules/`uname -r`/kernel -name MODULE_NAME.ko". */ char *modulesdir[] = { NULL, NULL }; - asprintf (&modulesdir[0], MODULEDIRFMT "/kernel", release); - if (modulesdir[0] == NULL) + if (asprintf (&modulesdir[0], MODULEDIRFMT "/kernel", release) < 0) return -1; FTS *fts = fts_open (modulesdir, FTS_LOGICAL | FTS_NOSTAT, NULL); @@ -417,9 +415,8 @@ dwfl_linux_kernel_module_section_address const GElf_Shdr *shdr __attribute__ ((unused)), Dwarf_Addr *addr) { - char *sysfile = NULL; - asprintf (&sysfile, SECADDRDIRFMT "%s", modname, secname); - if (sysfile == NULL) + char *sysfile; + if (asprintf (&sysfile, SECADDRDIRFMT "%s", modname, secname)) return ENOMEM; FILE *f = fopen (sysfile, "r"); @@ -453,9 +450,8 @@ dwfl_linux_kernel_module_section_address const bool is_init = !strncmp (secname, ".init", 5); if (is_init) { - sysfile = NULL; - asprintf (&sysfile, SECADDRDIRFMT "_%s", modname, &secname[1]); - if (sysfile == NULL) + if (asprintf (&sysfile, SECADDRDIRFMT "_%s", + modname, &secname[1]) < 0) return ENOMEM; f = fopen (sysfile, "r"); free (sysfile); @@ -469,10 +465,9 @@ dwfl_linux_kernel_module_section_address size_t namelen = strlen (secname); if (namelen >= MODULE_SECT_NAME_LEN) { - sysfile = NULL; int len = asprintf (&sysfile, SECADDRDIRFMT "%s", modname, secname); - if (sysfile == NULL) + if (len < 0) return ENOMEM; char *end = sysfile + len; do diff --git a/libelf/ChangeLog b/libelf/ChangeLog index 8d1f289d1..f3cf68972 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,7 +1,3 @@ -2007-01-30 Ulrich Drepper - - * nlist.c: Close file descriptor before returning. - 2006-10-13 Roland McGrath * elf32_updatenull.c: Look for and accept phdr also for ET_CORE. diff --git a/libelf/nlist.c b/libelf/nlist.c index b3a6af0d6..fd2209dfa 100644 --- a/libelf/nlist.c +++ b/libelf/nlist.c @@ -230,9 +230,6 @@ nlist (const char *filename, struct nlist *nl) /* We do not need the ELF descriptor anymore. */ (void) INTUSE(elf_end) (elf); - /* Neither the file descriptor. */ - (void) close (fd); - return 0; fail_dealloc: @@ -242,9 +239,6 @@ nlist (const char *filename, struct nlist *nl) /* We do not need the ELF descriptor anymore. */ (void) INTUSE(elf_end) (elf); - /* Neither the file descriptor. */ - (void) close (fd); - fail: /* We have to set all entries to zero. */ while (nl->n_name != NULL && nl->n_name[0] != '\0')