Skip to content

Commit 4579775

Browse files
committed
archive/tar: narrow trim range for formatter'formatString
Trim s[:len(b)-1] rather than s[:len(b)], since s[len(b)-1] is '/'.
1 parent 34a6028 commit 4579775

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

src/archive/tar/strconv.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,8 @@ func (f *formatter) formatString(b []byte, s string) {
7373
// in the V7 path field as a directory even though the full path
7474
// recorded elsewhere (e.g., via PAX record) contains no trailing slash.
7575
if len(s) > len(b) && b[len(b)-1] == '/' {
76-
i := len(b) - 2 // s[len(b)-1] == '/'
77-
for ; i >= 0; i-- {
78-
if s[i] != '/' {
79-
break
80-
}
81-
}
82-
b[i+1] = 0 // Replace trailing slash with NUL terminator
76+
n := len(strings.TrimRight(s[:len(b)-1], "/"))
77+
b[n] = 0 // Replace trailing slash with NUL terminator
8378
}
8479
}
8580

0 commit comments

Comments
 (0)