[klibc] [klibc:master] dash: shell: Fix clang warnings about "string plus integer"
klibc-bot for Antonio Ospite
ao2 at ao2.it
Sat Mar 28 09:24:04 PDT 2020
Commit-ID: 449b6b244204921fd048cb340fdc42c91b89149a
Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=449b6b244204921fd048cb340fdc42c91b89149a
Author: Antonio Ospite <ao2 at ao2.it>
AuthorDate: Sat, 15 Dec 2018 18:49:31 +0100
Committer: Ben Hutchings <ben at decadent.org.uk>
CommitDate: Sat, 28 Mar 2020 16:20:40 +0000
[klibc] dash: shell: Fix clang warnings about "string plus integer"
[ dash commit 604bd2b57a08817da8d757c5eb265dbe11ef3d39 ]
Building with clang results in some warnings about integer values being
added to strings:
-----------------------------------------------------------------------
eval.c:1138:13: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int]
p = " %s" + (1 - sep);
~~~~~~^~~~~~~~~~~
eval.c:1138:13: note: use array indexing to silence this warning
p = " %s" + (1 - sep);
^
& [ ]
1 warning generated.
...
jobs.c:1424:16: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int]
str = "\"}" + !(quoted & 1);
~~~~~~^~~~~~~~~~~~~~~
jobs.c:1424:16: note: use array indexing to silence this warning
str = "\"}" + !(quoted & 1);
^
& [ ]
1 warning generated.
-----------------------------------------------------------------------
While the code itself is fine and the warnings are indeed harmless,
fixing them also makes the semantic more explicit: what it is actually
being increased is the address which points to the start of the string
in order to skip the initial character when some conditions are met.
Signed-off-by: Antonio Ospite <ao2 at ao2.it>
Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben at decadent.org.uk>
---
usr/dash/eval.c | 3 ++-
usr/dash/jobs.c | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/usr/dash/eval.c b/usr/dash/eval.c
index ae83508b..dd144948 100644
--- a/usr/dash/eval.c
+++ b/usr/dash/eval.c
@@ -1081,7 +1081,8 @@ eprintlist(struct output *out, struct strlist *sp, int sep)
while (sp) {
const char *p;
- p = " %s" + (1 - sep);
+ p = " %s";
+ p += (1 - sep);
sep |= 1;
outfmt(out, p, sp->text);
sp = sp->next;
diff --git a/usr/dash/jobs.c b/usr/dash/jobs.c
index 009bbfee..b9ff1402 100644
--- a/usr/dash/jobs.c
+++ b/usr/dash/jobs.c
@@ -1394,7 +1394,8 @@ cmdputs(const char *s)
str = "${";
goto dostr;
case CTLENDVAR:
- str = "\"}" + !(quoted & 1);
+ str = "\"}";
+ str += !(quoted & 1);
quoted >>= 1;
subtype = 0;
goto dostr;
More information about the klibc
mailing list