diff options
author | Antonio Ospite <ao2@ao2.it> | 2018-12-15 18:49:31 +0100 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2020-03-28 16:20:40 +0000 |
commit | 449b6b244204921fd048cb340fdc42c91b89149a (patch) | |
tree | 8567edcaf7d15a221a1010b461ab16d0a8541669 | |
parent | 9d8d648e604026b32cad00a84ed6c29cbd157641 (diff) | |
download | klibc-449b6b244204921fd048cb340fdc42c91b89149a.tar.gz |
[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@ao2.it>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rw-r--r-- | usr/dash/eval.c | 3 | ||||
-rw-r--r-- | 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 ae83508ba160d2..dd144948a9fa87 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 009bbfeee47ec7..b9ff1402038451 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; |