From: Roy Marples Date: Thu, 8 Aug 2019 20:59:55 +0000 (+0100) Subject: script: optimise variable X-Git-Tag: v8.0.3~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c4ac8b06f9ddd423af9e46bc3c64f7d88c4c827e;p=thirdparty%2Fdhcpcd.git script: optimise variable --- diff --git a/src/script.c b/src/script.c index f2ee8b27..f34ead12 100644 --- a/src/script.c +++ b/src/script.c @@ -178,7 +178,7 @@ make_env(const struct interface *ifp, const char *reason) { struct dhcpcd_ctx *ctx = ifp->ctx; FILE *fp; - char **env, **envp, *buf, *bufp, *endp, *path; + char **env, **envp, *bufp, *endp, *path; size_t nenv; long buf_pos, i; int protocol = PROTO_LINK; @@ -459,20 +459,18 @@ dumplease: logerr(__func__); goto eexit; } -#ifdef HAVE_OPEN_MEMSTREAM - buf = ctx->script_buf; -#else + +#ifndef HAVE_OPEN_MEMSTREAM size_t buf_len = (size_t)buf_pos; if (ctx->script_buflen < buf_len) { - buf = realloc(ctx->script_buf, buf_len); + char *buf = realloc(ctx->script_buf, buf_len); if (buf == NULL) goto eexit; ctx->script_buf = buf; ctx->script_buflen = buf_len; } - buf = ctx->script_buf; rewind(fp); - if (fread(buf, sizeof(char), buf_len, fp) != buf_len) + if (fread(ctx->script_buf, sizeof(char), buf_len, fp) != buf_len) goto eexit; fclose(fp); fp = NULL; @@ -481,8 +479,8 @@ dumplease: /* Count the terminated env strings. * Assert that the terminations are correct. */ nenv = 0; - endp = buf + buf_pos; - for (bufp = buf; bufp < endp; bufp++) { + endp = ctx->script_buf + buf_pos; + for (bufp = ctx->script_buf; bufp < endp; bufp++) { if (*bufp == '\0') { #ifndef NDEBUG if (bufp + 1 < endp) @@ -500,7 +498,8 @@ dumplease: ctx->script_env = env; ctx->script_envlen = nenv; } - bufp = buf; + + bufp = ctx->script_buf; envp = ctx->script_env; *envp++ = bufp++; endp--; /* Avoid setting the last \0 to an invalid pointer */