From: Simon Glass Date: Mon, 19 Oct 2020 07:55:57 -0600 Subject: [PATCH 06/11] bootm: Use size rather than length for CONSOLE_ARG In-Reply-To: <20201019135602.3943835-1-sjg@chromium.org> References: <20201019135602.3943835-1-sjg@chromium.org> Message-ID: <20201019135602.3943835-7-sjg@chromium.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Use the size (including terminator) for in this function, rather than the length. This is arguably easier to follow, with the coming refactor. Signed-off-by: Simon Glass --- common/bootm.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/common/bootm.c b/common/bootm.c index fa2aecdbc68..bbe59752609 100644 --- a/common/bootm.c +++ b/common/bootm.c @@ -463,8 +463,8 @@ ulong bootm_disable_interrupts(void) return iflag; } -#define CONSOLE_ARG "console=" -#define CONSOLE_ARG_LEN (sizeof(CONSOLE_ARG) - 1) +#define CONSOLE_ARG "console=" +#define CONSOLE_ARG_SIZE sizeof(CONSOLE_ARG) int bootm_process_cmdline_env(bool do_silent) { @@ -498,7 +498,7 @@ int bootm_process_cmdline_env(bool do_silent) char *start = strstr(cmdline, CONSOLE_ARG); /* Allocate space for maximum possible new command line */ - buf = malloc(strlen(cmdline) + 1 + CONSOLE_ARG_LEN + 1); + buf = malloc(strlen(cmdline) + 1 + CONSOLE_ARG_SIZE); if (!buf) { debug("%s: out of memory\n", __func__); return -ENOSPC; @@ -506,13 +506,14 @@ int bootm_process_cmdline_env(bool do_silent) if (start) { char *end = strchr(start, ' '); - int num_start_bytes = start - cmdline + CONSOLE_ARG_LEN; + int start_bytes; - strncpy(buf, cmdline, num_start_bytes); + start_bytes = start - cmdline + CONSOLE_ARG_SIZE - 1; + strncpy(buf, cmdline, start_bytes); if (end) - strcpy(buf + num_start_bytes, end); + strcpy(buf + start_bytes, end); else - buf[num_start_bytes] = '\0'; + buf[start_bytes] = '\0'; } else { sprintf(buf, "%s %s", cmdline, CONSOLE_ARG); } -- 2.29.0.rc1.297.gfa9743e501-goog