39dcf47bc8
1/ Prevent an out-of-bounds write if sz is 0. 2/ Limit sz to INT_MAX, because the return value is an int, not an unsigned int (and because if INT_MAX is equal to SSIZE_MAX, man 2 read says "If count is greater than SSIZE_MAX, the result is unspecified.") 3/ Always null-terminate dst (unless sz is 0), because a return value of 0 because of an open() error (for example) is indistinguishable from a return value of 0 because of an empty file. 4/ Use an unsigned int for i (just like n), not an int. 5/ Check for snprintf() truncation.