From: Bruno Haible Date: Tue, 16 May 2017 18:02:20 +0000 (+0200) Subject: relocate: Simplify EMX specific code. X-Git-Tag: v1.0~6143 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=88fdf7f84a0b5965eb23a9ea8a24975cf4a06e1f;p=gnulib.git relocate: Simplify EMX specific code. * lib/relocatable.c (relocate): Assume pathname is non-NULL. Use ISSLASH macro consistently. Avoid dangerous string concatenation idiom. --- diff --git a/ChangeLog b/ChangeLog index 9eedc530b6..57e2aef7fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2017-05-16 Bruno Haible + + 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 sigpipe tests: Fix file list. diff --git a/lib/relocatable.c b/lib/relocatable.c index c42398ebbb..189aee4da8 100644 --- a/lib/relocatable.c +++ b/lib/relocatable.c @@ -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; }