use strchrnul() in place of strchr() and strlen()
[gitweb.git] / match-trees.c
index 7873cdec581eea66feab06c22b83ef7c27c7c5b6..e80b4af354f87caa7a5130660e9c9c530246b8be 100644 (file)
@@ -182,13 +182,10 @@ static int splice_tree(const unsigned char *hash1,
        enum object_type type;
        int status;
 
-       subpath = strchr(prefix, '/');
-       if (!subpath)
-               toplen = strlen(prefix);
-       else {
-               toplen = subpath - prefix;
+       subpath = strchrnul(prefix, '/');
+       toplen = subpath - prefix;
+       if (*subpath)
                subpath++;
-       }
 
        buf = read_sha1_file(hash1, &type, &sz);
        if (!buf)
@@ -215,7 +212,7 @@ static int splice_tree(const unsigned char *hash1,
        if (!rewrite_here)
                die("entry %.*s not found in tree %s",
                    toplen, prefix, sha1_to_hex(hash1));
-       if (subpath) {
+       if (*subpath) {
                status = splice_tree(rewrite_here, subpath, hash2, subtree);
                if (status)
                        return status;