According to http://linux.die.net/man/3/sprintf and http://www.cplusplus.com/reference/cstdio/sprintf/ sprintf() and family return the number of characters written on success. On failure, a negative value is returned. I would assume that an error could occur if the format string is malformed so a negative return value could indicate something other than a malloc() error. Does errno get set to indicate what the error was?
According to http://linux.die.net/man/3/sprintf and http://www.cplusplus.com/reference/cstdio/sprintf/ sprintf() and family return the number of characters written
Share
C++ defers to C and C does not require or mention
errnoin the description ofsprintf()and family (although for certain format specifiers, these functions are defined to callmbrtowc(), which may setEILSEQinerrno)POSIX requires that errno is set:
EILSEQ, EINVAL, EBADF, ENOMEM, EOVERFLOW are mentioned explicitly: http://pubs.opengroup.org/onlinepubs/9699919799/functions/fprintf.html