Created
January 29, 2021 01:11
-
-
Save jcabmora/8da32200d0390ec6b980bb7067a67842 to your computer and use it in GitHub Desktop.
subtle bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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