I discovered the default buffer is 64k. But I would expect the Scanner to be able to discover how big a buffer is available, and for example panic instead of silently corrupting memory (overwriting a data structure with the contents of the data read from the file) - are my expectations unreasonable?
I’m pretty sure this shouldn’t happen. Can you make a reproducible test case?
“Equivalent code” isn’t great. The devil is in the details - in your original paste I’d take a close look at what fp.parseLine does exactly. (That is, verify that you are acting in accordance with what the documentation says about the return value of scanner.Bytes.)
Is nothing wrong in what happen. In the source code of bufio says that
MaxScanTokenSize is the maximum size used to buffer a token
unless the user provides an explicit buffer with Scan.Buffer.
The actual maximum token size may be smaller as the buffer
may need to include, for instance, a newline.
MaxScanTokenSize = 64 * 1024
you did very well by extending initial buffer with scanner.Buffer(buf, maxCapacity).