Correctly notice empty sysroots in solib_find_1
authorGary Benson <gbenson@redhat.com>
Thu, 25 Jun 2015 08:54:12 +0000 (09:54 +0100)
committerGary Benson <gbenson@redhat.com>
Thu, 25 Jun 2015 08:54:12 +0000 (09:54 +0100)
Some parts of solib_find_1 should only operate if the sysroot
is nonempty after processing, but the logic that checked this
happened before trailing slashes were stripped so empty but
non-NULL sysroots were possible.  This commit moves the logic
so it correctly notices all empty sysroots.

gdb/ChangeLog:

* solib.c (solib_find_1): Set local variable sysroot to NULL if
it is the empty string after trailing slashes have been stripped.

gdb/ChangeLog
gdb/solib.c

index 4ff683dcac5c3652f3b51cf803e92733f2d50870..659f9b78e20bfdd27badf06bb764271d021d3086 100644 (file)
@@ -1,3 +1,8 @@
+2015-06-25  Gary Benson  <gbenson@redhat.com>
+
+       * solib.c (solib_find_1): Set local variable sysroot to NULL if
+       it is the empty string after trailing slashes have been stripped.
+
 2015-06-25  Gary Benson  <gbenson@redhat.com>
 
        * exec.c (exec_file_locate_attach): Remove gdb_sysroot NULL check.
index ed1bc253ecb80236e62a96b8c5bcf775d8ce630c..eb933c044d55b99f6042ff88ec4eca0ce9d6bf30 100644 (file)
@@ -158,6 +158,7 @@ solib_find_1 (char *in_pathname, int *fd, int is_solib)
   const char *fskind = effective_target_file_system_kind ();
   struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
   char *sysroot = gdb_sysroot;
+  int prefix_len, orig_prefix_len;
 
   /* If the absolute prefix starts with "target:" but the filesystem
      accessed by the target_fileio_* methods is the local filesystem
@@ -168,17 +169,16 @@ solib_find_1 (char *in_pathname, int *fd, int is_solib)
   if (is_target_filename (sysroot) && target_filesystem_is_local ())
     sysroot += strlen (TARGET_SYSROOT_PREFIX);
 
-  if (*sysroot == '\0')
-    sysroot = NULL;
-  else
-    {
-      int prefix_len = strlen (sysroot);
+  /* Strip any trailing slashes from the absolute prefix.  */
+  prefix_len = orig_prefix_len = strlen (sysroot);
 
-      /* Remove trailing slashes from absolute prefix.  */
-      while (prefix_len > 0
-            && IS_DIR_SEPARATOR (sysroot[prefix_len - 1]))
-       prefix_len--;
+  while (prefix_len > 0 && IS_DIR_SEPARATOR (sysroot[prefix_len - 1]))
+    prefix_len--;
 
+  if (prefix_len == 0)
+    sysroot = NULL;
+  else if (prefix_len != orig_prefix_len)
+    {
       sysroot = savestring (sysroot, prefix_len);
       make_cleanup (xfree, sysroot);
     }
This page took 0.028268 seconds and 4 git commands to generate.