* PATCH: don't increment a null pointer in set -A
@ 2018-04-06 16:06 Oliver Kiddle
0 siblings, 0 replies; only message in thread
From: Oliver Kiddle @ 2018-04-06 16:06 UTC (permalink / raw)
To: Zsh workers
In coverity CID 1255831, it warns about this code which handles set -A
and set +A. There's no actual bug here but the following change is more
efficient (thanks to arrlen_gt) and makes the code somewhat cleaner at
least in my opinion. In the case of set -A, we assign a to NULL and then
increment it with each loop. Incrementing a NULL pointer is harmless but
still a bit icky.
Unfortunately, coverity will probably still complain about this because
it can't connect the fact that (!*args) will only ever be true when a
wasn't/isn't null.
Oliver
diff --git a/Src/builtin.c b/Src/builtin.c
index fb59738f3..73cfe7ad1 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -695,13 +695,11 @@ bin_set(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
char **a = NULL, **y;
int len = arrlen(args);
- if (array < 0 && (a = getaparam(arrayname))) {
- int al = arrlen(a);
-
- if (al > len)
- len = al;
+ if (array < 0 && (a = getaparam(arrayname)) && arrlen_gt(a, len)) {
+ a += len;
+ len += arrlen(a);
}
- for (x = y = zalloc((len + 1) * sizeof(char *)); len--; a++) {
+ for (x = y = zalloc((len + 1) * sizeof(char *)); len--;) {
if (!*args)
args = a;
*y++ = ztrdup(*args++);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2018-04-06 16:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-06 16:06 PATCH: don't increment a null pointer in set -A Oliver Kiddle
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).