OneBug All write-ups

Go

Go bugs, explained.

Go compiles your bug and ships it. Copies where you expected references, references where you expected copies, and interfaces that are never quite nil - all of it silent, most of it invisible to go vet.

Go len(string) counts bytes, not the characters you see len("cafe") with an accented e returns 5, not 4, so a four-character limit rejects a valid name. Go strings are UTF-8 bytes. Here is the rune-count fix. Go fatal error: concurrent map writes (and the fix) 500 goroutines wrote one map and Go killed the whole process - and recover() cannot save it. Why concurrent map writes are fatal, and how to fix them. Go: assignment to entry in nil map (why writes panic) Writing to a nil map panics in Go while reading it works fine. Here is why var makes a nil map, not an empty one, and the one-line make fix. Go closures capture variables, not values (1.22 or not) Every closure built in the loop returns the same final value, because they all share one captured variable. Why Go 1.22 didn't fix this shape. Go data race: 500 goroutines, a counter that loses count count++ is a read-modify-write, so unsynchronized goroutines overwrite each other's updates. Real -race output, the fix, and the fix that isn't. Go typed nil: err == nil is false after you returned nil Returning a nil *Error through the error interface makes err != nil true on success. Why Go interfaces carry a type, and the one-word fix. Go range loop doesn't update structs: the value-copy trap A Go range loop over a struct slice silently fails to update fields because it copies each element. Here is why, and the one-line index fix. Go slice bug: nums[:0] silently overwrites your input array Appending to a reslice like nums[:0] shares memory with the caller's array, so filtering silently corrupts the original data. Here's why, and the fix.