lib/util: fix spdk_strerror() empty string return
If __USE_GNU is set, spdk_strerror() returns empty string instead of "Unknown error %d". if unknown error code provided. The reason is that on unknown errors, `strerror_r()` will return provided buffer, (in our case, `buf` is returned) then `snprintf()` will write to `buf` having `buf` as input argument because `new_buffer` == `buf`, which results in an empty string. This patch fixes the above issue by first checking if `buf` == `new_buffer`. Change-Id: I838ebf47d115b58cee3145991243bc9ebaeb651d Signed-off-by: Vitaliy Mysak <vitaliy.mysak@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/460825 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Paul Luse <paul.e.luse@intel.com> Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
This commit is contained in:
parent
719ee8be1f
commit
772db556af
@ -341,7 +341,9 @@ spdk_strerror_r(int errnum, char *buf, size_t buflen)
|
||||
#if defined(__USE_GNU)
|
||||
char *new_buffer;
|
||||
new_buffer = strerror_r(errnum, buf, buflen);
|
||||
if (new_buffer != NULL) {
|
||||
if (new_buffer == buf) {
|
||||
rc = 0;
|
||||
} else if (new_buffer != NULL) {
|
||||
snprintf(buf, buflen, "%s", new_buffer);
|
||||
rc = 0;
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user