summary refs log tree commit diff
path: root/src/eval.c
diff options
context:
space:
mode:
authorAntonio Ospite <ao2@ao2.it>2018-12-15 18:49:31 +0100
committerHerbert Xu <herbert@gondor.apana.org.au>2019-02-25 12:52:11 +0800
commit604bd2b57a08817da8d757c5eb265dbe11ef3d39 (patch)
tree09a5802503af4702f8557d786657c705a69df90f /src/eval.c
parenteval: Only restore exit status on exit/return (diff)
downloaddash-604bd2b57a08817da8d757c5eb265dbe11ef3d39.tar.gz
dash-604bd2b57a08817da8d757c5eb265dbe11ef3d39.zip
shell: Fix clang warnings about "string plus integer"
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>
Diffstat (limited to '')
-rw-r--r--src/eval.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/eval.c b/src/eval.c
index 514922e..1aad31a 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1132,7 +1132,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;