Skip to content

Instantly share code, notes, and snippets.

@jcabmora
Created January 29, 2021 01:11
Show Gist options
  • Save jcabmora/8da32200d0390ec6b980bb7067a67842 to your computer and use it in GitHub Desktop.
Save jcabmora/8da32200d0390ec6b980bb7067a67842 to your computer and use it in GitHub Desktop.
subtle bug
package main
import (
"bufio"
"fmt"
"os"
)
// test it:
// eval printf '...............%s\\n' `printf '{#..$}%.0s' {1..16}` | go run buggy.go
func main() {
scanner := bufio.NewScanner(os.Stdin)
allLines := [][]byte{}
linecount := 0
scanner.Scan()
lineBytes := scanner.Bytes()
allLines = append(allLines, lineBytes)
firstLine := string(lineBytes)
for scanner.Scan() {
linecount += 1
lineBytes = scanner.Bytes()
allLines = append(allLines, lineBytes)
line := string(allLines[0])
if line != firstLine {
fmt.Printf("Whaaat???? Line %d\n", linecount)
os.Exit(1)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment