Check that return value of snprintf(3) is not negative, rather than only -1.
This commit is contained in:
parent
84b578b0e4
commit
ab857595d7
@ -69,7 +69,7 @@ sanitize_url(const char *path)
|
|||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
r = snprintf(buf, sizeof(buf) - 1, "%s/%s", dirnp, basenp);
|
r = snprintf(buf, sizeof(buf) - 1, "%s/%s", dirnp, basenp);
|
||||||
if (r == -1 || r >= (int)sizeof(buf) - 1)
|
if (r < 0 || r >= (int)sizeof(buf) - 1)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
res = buf;
|
res = buf;
|
||||||
|
@ -445,7 +445,7 @@ xbps_set_cachedir(const char *dir)
|
|||||||
assert(dir != NULL);
|
assert(dir != NULL);
|
||||||
|
|
||||||
r = snprintf(res, sizeof(res) - 1, "%s/%s", xbps_get_rootdir(), dir);
|
r = snprintf(res, sizeof(res) - 1, "%s/%s", xbps_get_rootdir(), dir);
|
||||||
if (r == -1 || r >= (int)sizeof(res) - 1) {
|
if (r < 0 || r >= (int)sizeof(res) - 1) {
|
||||||
/* If error or truncated set to default */
|
/* If error or truncated set to default */
|
||||||
cachedir = XBPS_CACHE_PATH;
|
cachedir = XBPS_CACHE_PATH;
|
||||||
return;
|
return;
|
||||||
@ -462,7 +462,7 @@ xbps_get_cachedir(void)
|
|||||||
if (cachedir == NULL) {
|
if (cachedir == NULL) {
|
||||||
r = snprintf(res, sizeof(res) - 1, "%s/%s",
|
r = snprintf(res, sizeof(res) - 1, "%s/%s",
|
||||||
xbps_get_rootdir(), XBPS_CACHE_PATH);
|
xbps_get_rootdir(), XBPS_CACHE_PATH);
|
||||||
if (r == -1 || r >= (int)sizeof(res) - 1)
|
if (r < 0 || r >= (int)sizeof(res) - 1)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
cachedir = res;
|
cachedir = res;
|
||||||
|
Loading…
Reference in New Issue
Block a user