[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] tools/firmware/hvmloader/smbios.c::hvm_write_smbios_tables()


  • To: "List: Xen Developers" <xen-devel@xxxxxxxxxxxxxxxxxxx>
  • From: "Jun Koi" <junkoi2004@xxxxxxxxx>
  • Date: Fri, 7 Dec 2007 17:37:55 +0900
  • Delivery-date: Fri, 07 Dec 2007 00:38:32 -0800
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=SJVmHvhTbMK47qU+JE0yv14IRQXkMkKcRS2xD9F6a5SE5Xoz3z+Dbg5Q151tA+YebBWsT4gEvBTVZm7af4Tm6nN/Ss5ZciZqdSq6qCg5GNPFseNGL5LUoZRMFmHOaUrDZsLYhM3botxAdWvkYVuYAYKe+WN5g0Klt//OxYCyS00=
  • List-id: Xen developer discussion <xen-devel.lists.xensource.com>

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@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.