Hacker News new | ask | show | jobs
by Safety1stClyde 3373 days ago
Thank you for posting.

> If you know some basic C, take a look at this block of code, and see if you can find a clue as to what went wrong:

> char *filename="models/";

> strcat(filename,"bullet");

> strcat(filename,".h3d");

That code being written in the first place does not inspire confidence. "strcat" has almost no valid use cases, and the suggested solution of using a fixed-size buffer is likely to lead to further instances of exactly the same variety of error at some time in the future.

> char filename[256];

The sane solution here is to use strncat or another, more appropriate, function such as snprintf. The length of the buffer should at least be a macro rather than a magic number.