From ab857595d7cd24b86eb44cea0f4cf14b2a6f80cd Mon Sep 17 00:00:00 2001 From: Juan RP Date: Fri, 21 Jan 2011 00:32:46 +0100 Subject: [PATCH] Check that return value of snprintf(3) is not negative, rather than only -1. --- bin/xbps-repo/repository.c | 2 +- lib/util.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/xbps-repo/repository.c b/bin/xbps-repo/repository.c index b146c891..8cba9ecc 100644 --- a/bin/xbps-repo/repository.c +++ b/bin/xbps-repo/repository.c @@ -69,7 +69,7 @@ sanitize_url(const char *path) goto out; 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; res = buf; diff --git a/lib/util.c b/lib/util.c index 33009381..b4061c35 100644 --- a/lib/util.c +++ b/lib/util.c @@ -445,7 +445,7 @@ xbps_set_cachedir(const char *dir) assert(dir != NULL); 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 */ cachedir = XBPS_CACHE_PATH; return; @@ -462,7 +462,7 @@ xbps_get_cachedir(void) if (cachedir == NULL) { r = snprintf(res, sizeof(res) - 1, "%s/%s", xbps_get_rootdir(), XBPS_CACHE_PATH); - if (r == -1 || r >= (int)sizeof(res) - 1) + if (r < 0 || r >= (int)sizeof(res) - 1) return NULL; cachedir = res;