From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36726) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YqITk-000829-2w for qemu-devel@nongnu.org; Thu, 07 May 2015 05:52:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YqITf-0001RO-CA for qemu-devel@nongnu.org; Thu, 07 May 2015 05:52:28 -0400 Received: from mailapp01.imgtec.com ([195.59.15.196]:45243) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YqITf-0001RC-74 for qemu-devel@nongnu.org; Thu, 07 May 2015 05:52:23 -0400 Message-ID: <554B35D3.2050908@imgtec.com> Date: Thu, 7 May 2015 10:52:19 +0100 From: Leon Alrae MIME-Version: 1.0 References: <1430924229-20469-1-git-send-email-leon.alrae@imgtec.com> <1430924229-20469-5-git-send-email-leon.alrae@imgtec.com> In-Reply-To: Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 4/4] semihosting: add --semihosting-config arg sub-argument List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Liviu Ionescu Cc: peter.maydell@linaro.org, christopher.covington@linaro.org, qemu-devel@nongnu.org, matthew.fortune@imgtec.com On 07/05/2015 07:51, Liviu Ionescu wrote: > >> On 06 May 2015, at 17:57, Leon Alrae wrote: >> >> +static int add_semihosting_arg(const char *name, const char *val, void *opaque) >> +{ >> + SemihostingConfig *s = opaque; >> + if (strcmp(name, "arg") == 0) { >> + s->argc++; >> + s->argv = g_realloc(s->argv, s->argc * sizeof(void *)); >> + s->argv[s->argc - 1] = val; >> + } >> + return 0; >> +} > > being done at init time probably it has no impact, but, as a matter of style, I would avoid iterating realloc when the buffer size is actually known. At this point QEMU doesn't know the buffer size, thus we need to traverse the list of sub-arguments to determine the number of args and also to get the value (i.e. string) of each arg. > > is it that difficult to count the "arg"s and correctly alloc the array? This probably would require going through the list twice which wouldn't be better in my opinion. Leon