[pacman-dev] [PATCH] Fix clang 8 string-plus-int warnings
Clang 8 warns that adding a string to an integer does not append to string. Indeed it doesn't, but that was not the intentetion. Use array indexing as suggested by the compiler to silence the warning. There should be no functional change. Example of warning message: alpm.c:71:54: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int] sprintf(hookdir, "%s%s", myhandle->root, SYSHOOKDIR + 1); ~~~~~~~~~~~^~~ alpm.c:71:54: note: use array indexing to silence this warning sprintf(hookdir, "%s%s", myhandle->root, SYSHOOKDIR + 1); ^ & [ ] 1 warning generated. --- lib/libalpm/alpm.c | 2 +- src/pacman/conf.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index 0f3db6f4..bd7a129a 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -68,7 +68,7 @@ alpm_handle_t SYMEXPORT *alpm_initialize(const char *root, const char *dbpath, * with a slash) correctly, we skip SYSHOOKDIR[0]; the regular +1 therefore * disappears from the allocation */ MALLOC(hookdir, strlen(myhandle->root) + strlen(SYSHOOKDIR), goto nomem); - sprintf(hookdir, "%s%s", myhandle->root, SYSHOOKDIR + 1); + sprintf(hookdir, "%s%s", myhandle->root, &SYSHOOKDIR[1]); myhandle->hookdirs = alpm_list_add(NULL, hookdir); /* set default database extension */ diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 3b79fbc7..2d8518c4 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -975,11 +975,11 @@ int setdefaults(config_t *c) if(c->rootdir) { char path[PATH_MAX]; if(!c->dbpath) { - snprintf(path, PATH_MAX, "%s/%s", c->rootdir, DBPATH + 1); + snprintf(path, PATH_MAX, "%s/%s", c->rootdir, &DBPATH[1]); SETDEFAULT(c->dbpath, strdup(path)); } if(!c->logfile) { - snprintf(path, PATH_MAX, "%s/%s", c->rootdir, LOGFILE + 1); + snprintf(path, PATH_MAX, "%s/%s", c->rootdir, &LOGFILE[1]); SETDEFAULT(c->logfile, strdup(path)); } } else { -- 2.21.0
On 04/05/19 at 12:02am, Rikard Falkeborn wrote:
Clang 8 warns that adding a string to an integer does not append to string. Indeed it doesn't, but that was not the intentetion. Use array indexing as suggested by the compiler to silence the warning. There should be no functional change.
Example of warning message:
alpm.c:71:54: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int] sprintf(hookdir, "%s%s", myhandle->root, SYSHOOKDIR + 1); ~~~~~~~~~~~^~~ alpm.c:71:54: note: use array indexing to silence this warning sprintf(hookdir, "%s%s", myhandle->root, SYSHOOKDIR + 1); ^ & [ ] 1 warning generated. --- lib/libalpm/alpm.c | 2 +- src/pacman/conf.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
I think this warning is dumb, but I guess the fix doesn't hurt anything. ACK
On 5/4/19 8:02 am, Rikard Falkeborn wrote:
Clang 8 warns that adding a string to an integer does not append to string. Indeed it doesn't, but that was not the intentetion. Use array indexing as suggested by the compiler to silence the warning. There should be no functional change.
Example of warning message:
alpm.c:71:54: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int] sprintf(hookdir, "%s%s", myhandle->root, SYSHOOKDIR + 1); ~~~~~~~~~~~^~~ alpm.c:71:54: note: use array indexing to silence this warning sprintf(hookdir, "%s%s", myhandle->root, SYSHOOKDIR + 1); ^ & [ ] 1 warning generated.
Ack. My solution was to switch back to gcc!
--- lib/libalpm/alpm.c | 2 +- src/pacman/conf.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index 0f3db6f4..bd7a129a 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -68,7 +68,7 @@ alpm_handle_t SYMEXPORT *alpm_initialize(const char *root, const char *dbpath, * with a slash) correctly, we skip SYSHOOKDIR[0]; the regular +1 therefore * disappears from the allocation */ MALLOC(hookdir, strlen(myhandle->root) + strlen(SYSHOOKDIR), goto nomem); - sprintf(hookdir, "%s%s", myhandle->root, SYSHOOKDIR + 1); + sprintf(hookdir, "%s%s", myhandle->root, &SYSHOOKDIR[1]); myhandle->hookdirs = alpm_list_add(NULL, hookdir);
/* set default database extension */ diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 3b79fbc7..2d8518c4 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -975,11 +975,11 @@ int setdefaults(config_t *c) if(c->rootdir) { char path[PATH_MAX]; if(!c->dbpath) { - snprintf(path, PATH_MAX, "%s/%s", c->rootdir, DBPATH + 1); + snprintf(path, PATH_MAX, "%s/%s", c->rootdir, &DBPATH[1]); SETDEFAULT(c->dbpath, strdup(path)); } if(!c->logfile) { - snprintf(path, PATH_MAX, "%s/%s", c->rootdir, LOGFILE + 1); + snprintf(path, PATH_MAX, "%s/%s", c->rootdir, &LOGFILE[1]); SETDEFAULT(c->logfile, strdup(path)); } } else {
participants (3)
-
Allan McRae
-
Andrew Gregory
-
Rikard Falkeborn