From patchwork Mon Feb 3 14:36:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 235852 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Mon, 3 Feb 2020 07:36:04 -0700 Subject: [PATCH v2 18/32] sandbox: Ensure that long-options array is terminated In-Reply-To: <20200203143618.74619-1-sjg@chromium.org> References: <20200203143618.74619-1-sjg@chromium.org> Message-ID: <20200203073614.v2.18.I6168badb553fa92db60d2539b78087eac6dfc68e@changeid> The last member of this array is supposed to be all zeroes according to the getopt_long() man page. Fix the function to do this. Signed-off-by: Simon Glass --- Changes in v2: None arch/sandbox/cpu/os.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 60011f7abc..f7c73e3a0b 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -284,7 +284,7 @@ int os_parse_args(struct sandbox_state *state, int argc, char *argv[]) /* dynamically construct the arguments to the system getopt_long */ short_opts = malloc(sizeof(*short_opts) * num_options * 2 + 1); - long_opts = malloc(sizeof(*long_opts) * num_options); + long_opts = malloc(sizeof(*long_opts) * (num_options + 1)); if (!short_opts || !long_opts) return 1; @@ -314,6 +314,7 @@ int os_parse_args(struct sandbox_state *state, int argc, char *argv[]) /* we need to handle output ourselves since u-boot provides printf */ opterr = 0; + memset(&long_opts[num_options], '\0', sizeof(*long_opts)); /* * walk all of the options the user gave us on the command line, * figure out what u-boot option structure they belong to (via