Message ID | 1457504091-31887-1-git-send-email-peterx@redhat.com |
---|---|
State | New |
Headers | show |
On Wed, 03/09 14:14, Peter Xu wrote: > Use heap rather than stack for kcmdline. > > Signed-off-by: Peter Xu <peterx@redhat.com> > --- > hw/i386/multiboot.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/hw/i386/multiboot.c b/hw/i386/multiboot.c > index 9e164e6..bc45394 100644 > --- a/hw/i386/multiboot.c > +++ b/hw/i386/multiboot.c > @@ -324,10 +324,9 @@ int load_multiboot(FWCfgState *fw_cfg, > } > > /* Commandline support */ > - char kcmdline[strlen(kernel_filename) + strlen(kernel_cmdline) + 2]; > - snprintf(kcmdline, sizeof(kcmdline), "%s %s", > - kernel_filename, kernel_cmdline); > + char *kcmdline = g_strdup_printf("%s %s", kernel_filename, kernel_cmdline); > stl_p(bootinfo + MBI_CMDLINE, mb_add_cmdline(&mbs, kcmdline)); > + g_free(kcmdline); > > stl_p(bootinfo + MBI_BOOTLOADER, mb_add_bootloader(&mbs, bootloader_name)); While at it, it's better to move the variable declaration to the beginning of function. Fam
On Wed, Mar 09, 2016 at 03:42:59PM +0800, Fam Zheng wrote: > On Wed, 03/09 14:14, Peter Xu wrote: > > Use heap rather than stack for kcmdline. > > > > Signed-off-by: Peter Xu <peterx@redhat.com> > > --- > > hw/i386/multiboot.c | 5 ++--- > > 1 file changed, 2 insertions(+), 3 deletions(-) > > > > diff --git a/hw/i386/multiboot.c b/hw/i386/multiboot.c > > index 9e164e6..bc45394 100644 > > --- a/hw/i386/multiboot.c > > +++ b/hw/i386/multiboot.c > > @@ -324,10 +324,9 @@ int load_multiboot(FWCfgState *fw_cfg, > > } > > > > /* Commandline support */ > > - char kcmdline[strlen(kernel_filename) + strlen(kernel_cmdline) + 2]; > > - snprintf(kcmdline, sizeof(kcmdline), "%s %s", > > - kernel_filename, kernel_cmdline); > > + char *kcmdline = g_strdup_printf("%s %s", kernel_filename, kernel_cmdline); > > stl_p(bootinfo + MBI_CMDLINE, mb_add_cmdline(&mbs, kcmdline)); > > + g_free(kcmdline); > > > > stl_p(bootinfo + MBI_BOOTLOADER, mb_add_bootloader(&mbs, bootloader_name)); > > While at it, it's better to move the variable declaration to the beginning of > function. Yes, I can do that. Let me post v2. Thanks. Peter
diff --git a/hw/i386/multiboot.c b/hw/i386/multiboot.c index 9e164e6..bc45394 100644 --- a/hw/i386/multiboot.c +++ b/hw/i386/multiboot.c @@ -324,10 +324,9 @@ int load_multiboot(FWCfgState *fw_cfg, } /* Commandline support */ - char kcmdline[strlen(kernel_filename) + strlen(kernel_cmdline) + 2]; - snprintf(kcmdline, sizeof(kcmdline), "%s %s", - kernel_filename, kernel_cmdline); + char *kcmdline = g_strdup_printf("%s %s", kernel_filename, kernel_cmdline); stl_p(bootinfo + MBI_CMDLINE, mb_add_cmdline(&mbs, kcmdline)); + g_free(kcmdline); stl_p(bootinfo + MBI_BOOTLOADER, mb_add_bootloader(&mbs, bootloader_name));
Use heap rather than stack for kcmdline. Signed-off-by: Peter Xu <peterx@redhat.com> --- hw/i386/multiboot.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)