2007-01-10 Roland McGrath <roland@redhat.com>
authorRoland McGrath <roland@redhat.com>
Thu, 11 Jan 2007 05:06:16 +0000 (05:06 +0000)
committerRoland McGrath <roland@redhat.com>
Thu, 11 Jan 2007 05:06:16 +0000 (05:06 +0000)
* 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/ChangeLog
libdwfl/find-debuginfo.c
libdwfl/linux-kernel-modules.c
libelf/ChangeLog
libelf/nlist.c

index e14cce9..67ecfe7 100644 (file)
@@ -1,5 +1,12 @@
 2007-01-10  Roland McGrath  <roland@redhat.com>
 
+       * 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  <roland@redhat.com>
index a99fd14..ca1fadc 100644 (file)
@@ -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));
index 4d4194a..a398638 100644 (file)
@@ -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
index 8d1f289..f3cf689 100644 (file)
@@ -1,7 +1,3 @@
-2007-01-30  Ulrich Drepper  <drepper@redhat.com>
-
-       * nlist.c: Close file descriptor before returning.
-
 2006-10-13  Roland McGrath  <roland@redhat.com>
 
        * elf32_updatenull.c: Look for and accept phdr also for ET_CORE.
index b3a6af0..fd2209d 100644 (file)
@@ -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')