Show HN: SLFG: We Made Gets() Safe. Everyone Said It Was Impossible
For decades, C programmers banned gets(). We found a way.
Two simple rules. Four lines of code. Perfect safety.
No more fgets() complexity. No more buffer overflows.
Two simple rules. Four lines of code. Perfect safety.
No more fgets() complexity. No more buffer overflows.
2 comments
[ 4.3 ms ] story [ 11.8 ms ] threadgo back to python land.
> buffer[4] = '\n' — puts a newline at the last position
> gets(buffer) — the function stops when it hits that newline
But gets() doesn't stop when it hits that newline. It stops when a newline appears in the input stream, not in the buffer the input is being copied to.
Besides, good luck finding a modern compiler that still supports gets() at all.