]> Savannah Git Hosting - gnulib.git/commitdiff
relocate: Simplify EMX specific code.
authorBruno Haible <bruno@clisp.org>
Tue, 16 May 2017 18:02:20 +0000 (20:02 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 16 May 2017 18:02:20 +0000 (20:02 +0200)
* lib/relocatable.c (relocate): Assume pathname is non-NULL. Use
ISSLASH macro consistently. Avoid dangerous string concatenation idiom.

ChangeLog
lib/relocatable.c

index 9eedc530b6d2de296f9f2f34227f8c9067eea1a3..57e2aef7fdd6a513111db50a617306867a52902c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-05-16  Bruno Haible  <bruno@clisp.org>
+
+       relocate: Simplify EMX specific code.
+       * lib/relocatable.c (relocate): Assume pathname is non-NULL. Use
+       ISSLASH macro consistently. Avoid dangerous string concatenation idiom.
+
 2017-05-16  Bruno Haible  <bruno@clisp.org>
 
        sigpipe tests: Fix file list.
index c42398ebbb7da61ca67bff6f297e33cd17587186..189aee4da814a151d14f7ac59cfe13dfa86a34f8 100644 (file)
@@ -542,27 +542,26 @@ relocate (const char *pathname)
 # ifdef __KLIBC__
 #  undef strncmp
 
-  if (pathname && strncmp (pathname, "/@unixroot", 10) == 0
-      && (pathname[10] == '\0' || pathname[10] == '/' || pathname[10] == '\\'))
+  if (strncmp (pathname, "/@unixroot", 10) == 0
+      && (pathname[10] == '\0' || ISSLASH (pathname[10])))
     {
       /* kLIBC itself processes /@unixroot prefix */
-
       return pathname;
     }
   else
 # endif
-  if (pathname && ISSLASH (pathname[0]))
+  if (ISSLASH (pathname[0]))
     {
       const char *unixroot = getenv ("UNIXROOT");
 
-      if (unixroot && HAS_DEVICE (unixroot) && !unixroot[2])
+      if (unixroot && HAS_DEVICE (unixroot) && unixroot[2] == '\0')
         {
           char *result = (char *) xmalloc (2 + strlen (pathname) + 1);
 #ifdef NO_XMALLOC
           if (result != NULL)
 #endif
             {
-              strcpy (result, unixroot);
+              memcpy (result, unixroot, 2);
               strcpy (result + 2, pathname);
               return result;
             }