mmap(win32): avoid copy-on-write when it is unnecessary
[gitweb.git] / test-path-utils.c
index c3adcd87b8caa2028785483bbc01d85fd0f7a9d6..ba805b374c57a4e5ad2e6e4a4b9071a11c165afa 100644 (file)
@@ -8,21 +8,14 @@
  */
 static int normalize_ceiling_entry(struct string_list_item *item, void *unused)
 {
-       const char *ceil = item->string;
-       int len = strlen(ceil);
-       char buf[PATH_MAX+1];
+       char *ceil = item->string;
 
-       if (len == 0)
+       if (!*ceil)
                die("Empty path is not supported");
-       if (len > PATH_MAX)
-               die("Path \"%s\" is too long", ceil);
        if (!is_absolute_path(ceil))
                die("Path \"%s\" is not absolute", ceil);
-       if (normalize_path_copy(buf, ceil) < 0)
+       if (normalize_path_copy(ceil, ceil) < 0)
                die("Path \"%s\" could not be normalized", ceil);
-       len = strlen(buf);
-       free(item->string);
-       item->string = xstrdup(buf);
        return 1;
 }
 
@@ -56,7 +49,7 @@ static int test_function(struct test_data *data, char *(*func)(char *input),
                if (!data[i].from)
                        to = func(NULL);
                else {
-                       strcpy(buffer, data[i].from);
+                       xsnprintf(buffer, sizeof(buffer), "%s", data[i].from);
                        to = func(buffer);
                }
                if (!strcmp(to, data[i].to))
@@ -166,7 +159,7 @@ static struct test_data dirname_data[] = {
 int main(int argc, char **argv)
 {
        if (argc == 3 && !strcmp(argv[1], "normalize_path_copy")) {
-               char *buf = xmalloc(PATH_MAX + 1);
+               char *buf = xmallocz(strlen(argv[2]));
                int rv = normalize_path_copy(buf, argv[2]);
                if (rv)
                        buf = "++failed++";