The classic unbounded read: `gets()` into a fixed array
The classic unbounded read: `gets()` into a fixed array
Answer
void read_tag(void) { char buf[8]; gets(buf); /* no size argument exists */ printf("tag: %s\n", buf); }
There is no way to make this call safe, because `gets()` takes no length. It reads until a newline or end of file and writes every byte into `buf`, whatever the caller intended. The bound would have to come from the caller, and there is nowhere to put it.
Stallings & Brown 5e ch10 §10.1–10.2