gets performs an unbounded read from stdin and always risks buffer overflow.
Replace gets with fgets and a fixed buffer size.