...
The sprintf_m()
API separates out the return status of the function from information about the number of characters written. In this case, *count
is set to the number of characters written in buf
while the return value indicates the return status. Returning the status as the return value of the function increases the likelihood that a programmer will check the return status of the function.
One can thus amend the previous code example thus:
Code Block | ||
---|---|---|
| ||
int i;
ssize_t count = 0;
errno_t err;
for (i = 0; i < 9; ++i) {
if ((err = sprintf_m( buf + count, "%02x ", &count,
((u8 *)&slreg_num)[i])) != 0) {
/* handle print error */
}
}
if ((err = sprintf_m( buf + count, "%02x ", &count,
((u8 *)&slreg_num)[i]) ) != 0) {
/* handle print error */
}
|
Exceptions
ERR02-EX1: Null pointers are another example of an in-band error indicator. Use of the null pointers is not quite as bad because it is supported for by the language. According to C99 Section 6.3.2.3, "Pointers":
...