Verified Commit b42ff382 authored by Frank Sauerburger's avatar Frank Sauerburger
Browse files

Break if unexpected EOF

parent f21a7066
Pipeline #8019 passed with stage
in 18 seconds
......@@ -24,7 +24,9 @@ func ComputeHash(device string) {
r := bufio.NewReader(f)
b:= make([]byte, 0, 1024 * 1024)
for {
n := 1
for n > 0 {
n, err := io.ReadFull(r, b[:cap(b)])
b = b[:n]
if err != nil {
......@@ -37,10 +39,13 @@ func ComputeHash(device string) {
}
}
_, err = bh.Write(b[:n])
if err != nil {
fmt.Fprintf(os.Stderr, "Cannot compute hash: %s\n", err)
_, herr := bh.Write(b[:n])
if herr != nil {
fmt.Fprintf(os.Stderr, "Cannot compute hash: %s\n", herr)
}
if err == io.ErrUnexpectedEOF {
break
}
}
fmt.Printf("\nHash: %x\n", h.Sum(nil))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment