From 44f7ab3df3a16c7c866e75122aeb1d46b67b674b Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 26 Dec 2015 15:13:13 +0100 Subject: remove empty environment entires MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/sat.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/sat.c') diff --git a/src/sat.c b/src/sat.c index f84d44b..84140a4 100644 --- a/src/sat.c +++ b/src/sat.c @@ -70,6 +70,9 @@ main(int argc, char *argv[], char *envp[]) struct timespec ts; clockid_t clk; char *msg = NULL; + char *w; + char *r; + int removed_empty = 0; size_t n; if ((argc < 3) || (argv[1][0] == '-')) { @@ -104,6 +107,18 @@ main(int argc, char *argv[], char *envp[]) argc -= 2; argv += 2; + /* Remove empty environment entries */ + for (w = r = envp; *r; *r++) { + if (**r) { + *w++ = *r; + } else if (removed_empty == 0) { + fprintf(stderr, + "%s: warning: removed empty " + "environment entry.\n", argv0); + removed_empty = 0; + } + } + /* Construct message to send to the daemon. */ n = measure_array(argv) + measure_array(envp); if (!(msg = malloc(n + sizeof(clk) + sizeof(ts)))) -- cgit v1.2.3-70-g09d2