Nah, it's just that the author doesn't apply his criticisms of K&R to his own code. Specifically,
Originally Posted by Toliot
has undefined behavior if foo is NULL or points to an unterminated string, so (for example) his function (taken from chapter 47)
is just as incorrect and defective as the K&R 'copy' function he criticizes in the final chapter, and for the same reasons. (I therefore find it ironic and amusing that this function is basically meant to be a "safer" wrapper around fgets.) He uses %s everywhere without checking bounds, so the suggestion that he should go back and change it everywhere was just me being snide.
bstring read_line(const char *prompt)
bstring result = bgets((bNgetc)fgetc, stdin, '\n');
check_debug(result != NULL, "stdin closed.");
check(btrimws(result) == BSTR_OK, "Failed to trim.");
(For your enlightenment, if you have a string that might be unterminated and you want to print it without overstepping bounds, this is how you do it:
where MAX_STRING is the longest the array s can be. Usually this isn't necessary.)
printf("%.*s", MAX_STRING, s);
Really? I mean, I have nothing against the book, but it has fairly lukewarm reviews and I'm not sure why you'd suggest it over... well, any one of a thousand mediocre C books out there. What do you like about it?
Originally Posted by King Dude