Thread (12 messages) flat view 12 messages, 3 authors, 2016-06-15

Re: [PATCH 1/4] make_absolute_path(): Do not append redundant slash

From: Johannes Sixt <hidden>
Date: 2016-06-15 22:48:12

On Dienstag, 9. Februar 2010, Nguyễn Thái Ngọc Duy wrote:
quoted hunk ↗ jump to hunk
@@ -54,8 +54,9 @@ const char *make_absolute_path(const char *path)
 			if (len + strlen(last_elem) + 2 > PATH_MAX)
 				die ("Too long path name: '%s/%s'",
 						buf, last_elem);
-			buf[len] = '/';
-			strcpy(buf + len + 1, last_elem);
+			if (*buf != '/' || buf[1] != '\0')
+				buf[len++] = '/';
Huh? You are adding a slash unless buf is exactly "/". That is, when buf 
is "/foo/" you still add a slash? That's not exactly avoiding redundancy. 
(Disclaimer: I didn't analyze the rest of the function whether my claim is 
true.)
+			strcpy(buf + len, last_elem);
 			free(last_elem);
 			last_elem = NULL;
 		}
-- Hannes
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help