[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 03/14] relocatable: support UNIXROOT in relocate() on EMX
From: |
Bruno Haible |
Subject: |
Re: [PATCH 03/14] relocatable: support UNIXROOT in relocate() on EMX |
Date: |
Tue, 16 May 2017 20:06:57 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-75-generic; KDE/5.18.0; x86_64; ; ) |
Followup to this patch from 2014-12-09: A bit more consistent coding style:
- The argument 'pathname' must be non-NULL. No need to test it against NULL.
- Make use of ISSLASH macro consistently.
- For characters, I find a comparison with '\0' clearer than a boolean negation.
Limit boolean expressions to booleans.
- Better use the memcpy-before-strcpy idiom than strcpy-before-strcpy. The
former makes it clear that the programmer has thought about the length of the
strings.
2017-05-16 Bruno Haible <address@hidden>
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/lib/relocatable.c b/lib/relocatable.c
index c42398e..189aee4 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;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [PATCH 03/14] relocatable: support UNIXROOT in relocate() on EMX,
Bruno Haible <=