aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbb/concat_path_file.c7
-rw-r--r--libbb/last_char_is.c5
2 files changed, 9 insertions, 3 deletions
diff --git a/libbb/concat_path_file.c b/libbb/concat_path_file.c
index 61efa9c3e..c699a84f7 100644
--- a/libbb/concat_path_file.c
+++ b/libbb/concat_path_file.c
@@ -13,11 +13,14 @@ extern char *concat_path_file(const char *path, const char *filename)
13{ 13{
14 char *outbuf; 14 char *outbuf;
15 char *lc; 15 char *lc;
16 16
17 if (!path)
18 path="";
17 lc = last_char_is(path, '/'); 19 lc = last_char_is(path, '/');
18 if (filename[0] == '/') 20 if (filename[0] == '/')
19 filename++; 21 filename++;
20 outbuf = xmalloc(strlen(path)+strlen(filename)+1+(lc==NULL)); 22 outbuf = xmalloc(strlen(path)+strlen(filename)+1+(lc==NULL));
21 sprintf(outbuf, (lc==NULL ? "%s/%s" : "%s%s"), path, filename); 23 sprintf(outbuf, "%s%s%s", path, (lc==NULL)? "/" : "", filename);
24
22 return outbuf; 25 return outbuf;
23} 26}
diff --git a/libbb/last_char_is.c b/libbb/last_char_is.c
index a95e57c35..4e2ee92ed 100644
--- a/libbb/last_char_is.c
+++ b/libbb/last_char_is.c
@@ -28,7 +28,10 @@
28 */ 28 */
29char * last_char_is(const char *s, int c) 29char * last_char_is(const char *s, int c)
30{ 30{
31 char *sret = (char *)s+strlen(s)-1; 31 char *sret;
32 if (!s)
33 return NULL;
34 sret = (char *)s+strlen(s)-1;
32 if (sret>=s && *sret == c) { 35 if (sret>=s && *sret == c) {
33 return sret; 36 return sret;
34 } else { 37 } else {