jonm / SillyMUD

SillyMUD, a derivative of DikuMud
Other
8 stars 5 forks source link

Fixes a subtle bug in `file_to_string()`. #102

Closed jonm closed 4 years ago

jonm commented 4 years ago

This function reads characters up to 100 characters at a time, and is meant to add a \r after each newline; it relies on the behavior of fgets() that only reads up until a newline or EOF. Under an assumption that all the lines in the file to be read are less than 100 characters long, this works as expected, translating \n into \n\r. However, if a line is longer than 100 characters, this ends up inserting a \r into the middle of the line, since fgets() will also stop reading if it hits the maximum character limit even without finding a newline.