Jun Koi
2007-Dec-07 08:37 UTC
[Xen-devel] tools/firmware/hvmloader/smbios.c::hvm_write_smbios_tables()
The function hvm_write_smbios_tables() in tools/firmware/hvmloader/smbios.c looks complicated in unnecessary way to me. Part of it like this: ... /* build up human-readable Xen version string */ p = xen_version_str; len = 0; itoa(tmp, xen_major_version); tmp_len = strlen(tmp); len += tmp_len; if ( len >= sizeof(xen_version_str) ) goto error_out; strcpy(p, tmp); p += tmp_len; len++; if ( len >= sizeof(xen_version_str) ) goto error_out; *p = ''.''; p++; itoa(tmp, xen_minor_version); tmp_len = strlen(tmp); len += tmp_len; if ( len >= sizeof(xen_version_str) ) goto error_out; strcpy(p, tmp); p += tmp_len; tmp_len = strlen(xen_extra_version); len += tmp_len; if ( len >= sizeof(xen_version_str) ) goto error_out; strcpy(p, xen_extra_version); p += tmp_len; xen_version_str[sizeof(xen_version_str)-1] = ''\0''; .... Basically, these long code can be written in only 1 line, like this: snprintf(xen_version_str, sizeof(xen_version_str), "%u.%u%s", xen_major_version, xen_minor_version, xen_extra_verison); (This is from xen-3.1 source code) Thanks, Jun _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Jun Koi
2007-Dec-07 08:47 UTC
Re: [Xen-devel] tools/firmware/hvmloader/smbios.c::hvm_write_smbios_tables()
On 12/7/07, Keir Fraser <Keir.Fraser@cl.cam.ac.uk> wrote:> On 7/12/07 08:37, "Jun Koi" <junkoi2004@gmail.com> wrote: > > > Basically, these long code can be written in only 1 line, like this: > > > > snprintf(xen_version_str, sizeof(xen_version_str), "%u.%u%s", > > xen_major_version, xen_minor_version, xen_extra_verison); > > There is no snprintf() in hvmloader currently. >Hmmm... can''t we include stdio.h for it? It is userspace code anyway, no? Thanks, Jun _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Keir Fraser
2007-Dec-07 08:52 UTC
Re: [Xen-devel] tools/firmware/hvmloader/smbios.c::hvm_write_smbios_tables()
On 7/12/07 08:37, "Jun Koi" <junkoi2004@gmail.com> wrote:> Basically, these long code can be written in only 1 line, like this: > > snprintf(xen_version_str, sizeof(xen_version_str), "%u.%u%s", > xen_major_version, xen_minor_version, xen_extra_verison);There is no snprintf() in hvmloader currently. - Keir _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Keir Fraser
2007-Dec-07 08:55 UTC
Re: [Xen-devel] tools/firmware/hvmloader/smbios.c::hvm_write_smbios_tables()
On 7/12/07 08:47, "Jun Koi" <junkoi2004@gmail.com> wrote:>>> Basically, these long code can be written in only 1 line, like this: >>> >>> snprintf(xen_version_str, sizeof(xen_version_str), "%u.%u%s", >>> xen_major_version, xen_minor_version, xen_extra_verison); >> >> There is no snprintf() in hvmloader currently. >> > > Hmmm... can''t we include stdio.h for it? It is userspace code anyway, no?No, it''s guest firmware. -- Keir _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel