Skip to content

Commit e9ebeb0

Browse files
committed
fix: do not attempt to decode utf8
native xxd doesn't try to either
1 parent 90262b3 commit e9ebeb0

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

xxd.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"io"
77
"os"
8-
"unicode/utf8"
98
)
109

1110
func main() {
@@ -66,15 +65,12 @@ func XXD(r io.Reader, w io.Writer) error {
6665

6766
// Character values
6867
b := buf[:n]
69-
for len(b) > 0 {
70-
r, size := utf8.DecodeRune(b)
71-
72-
if int(r) > 0x1f && int(r) < 0x7f {
73-
fmt.Fprintf(w, "%v", string(r))
68+
for _, c := range b {
69+
if c > 0x1f && c < 0x7f {
70+
fmt.Fprintf(w, "%v", string(c))
7471
} else {
7572
fmt.Fprintf(w, ".")
7673
}
77-
b = b[size:]
7874
}
7975

8076
fmt.Fprintf(w, "\n")

0 commit comments

Comments
 (0)