Remove VIR_STRNDUP usage that subtracts from a non-NULL pointer

Use g_strndup in all the cases where we check upfront whether a pointer
is non-NULL and then use it to calculate the copied length.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Ján Tomko 2019-10-24 19:32:35 +02:00
parent 05e33d4f54
commit fa061c92ec

View File

@ -220,23 +220,23 @@ virSysinfoParsePPCSystem(const char *base, virSysinfoSystemDefPtr *sysdef)
cur = strchr(cur, ':') + 1; cur = strchr(cur, ':') + 1;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpaces(&cur); virSkipSpaces(&cur);
if (eol && VIR_STRNDUP(def->family, cur, eol - cur) < 0) if (eol)
goto cleanup; def->family = g_strndup(cur, eol - cur);
if ((cur = strstr(base, "model")) != NULL) { if ((cur = strstr(base, "model")) != NULL) {
cur = strchr(cur, ':') + 1; cur = strchr(cur, ':') + 1;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpaces(&cur); virSkipSpaces(&cur);
if (eol && VIR_STRNDUP(def->serial, cur, eol - cur) < 0) if (eol)
goto cleanup; def->serial = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "machine")) != NULL) { if ((cur = strstr(base, "machine")) != NULL) {
cur = strchr(cur, ':') + 1; cur = strchr(cur, ':') + 1;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpaces(&cur); virSkipSpaces(&cur);
if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0) if (eol)
goto cleanup; def->version = g_strndup(cur, eol - cur);
} }
if (!def->manufacturer && !def->product && !def->version && if (!def->manufacturer && !def->product && !def->version &&
@ -248,7 +248,6 @@ virSysinfoParsePPCSystem(const char *base, virSysinfoSystemDefPtr *sysdef)
*sysdef = def; *sysdef = def;
def = NULL; def = NULL;
ret = 0; ret = 0;
cleanup:
virSysinfoSystemDefFree(def); virSysinfoSystemDefFree(def);
return ret; return ret;
} }
@ -270,18 +269,17 @@ virSysinfoParsePPCProcessor(const char *base, virSysinfoDefPtr ret)
processor = &ret->processor[ret->nprocessor - 1]; processor = &ret->processor[ret->nprocessor - 1];
virSkipSpaces(&cur); virSkipSpaces(&cur);
if (eol && VIR_STRNDUP(processor->processor_socket_destination, if (eol)
cur, eol - cur) < 0) processor->processor_socket_destination = g_strndup(cur,
return -1; eol - cur);
base = cur; base = cur;
if ((cur = strstr(base, "cpu")) != NULL) { if ((cur = strstr(base, "cpu")) != NULL) {
cur = strchr(cur, ':') + 1; cur = strchr(cur, ':') + 1;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpaces(&cur); virSkipSpaces(&cur);
if (eol && VIR_STRNDUP(processor->processor_type, if (eol)
cur, eol - cur) < 0) processor->processor_type = g_strndup(cur, eol - cur);
return -1;
base = cur; base = cur;
} }
@ -289,9 +287,8 @@ virSysinfoParsePPCProcessor(const char *base, virSysinfoDefPtr ret)
cur = strchr(cur, ':') + 1; cur = strchr(cur, ':') + 1;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpaces(&cur); virSkipSpaces(&cur);
if (eol && VIR_STRNDUP(processor->processor_version, if (eol)
cur, eol - cur) < 0) processor->processor_version = g_strndup(cur, eol - cur);
return -1;
base = cur; base = cur;
} }
@ -354,23 +351,23 @@ virSysinfoParseARMSystem(const char *base, virSysinfoSystemDefPtr *sysdef)
cur = strchr(cur, ':') + 1; cur = strchr(cur, ':') + 1;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpaces(&cur); virSkipSpaces(&cur);
if (eol && VIR_STRNDUP(def->family, cur, eol - cur) < 0) if (eol)
goto cleanup; def->family = g_strndup(cur, eol - cur);
if ((cur = strstr(base, "model")) != NULL) { if ((cur = strstr(base, "model")) != NULL) {
cur = strchr(cur, ':') + 1; cur = strchr(cur, ':') + 1;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpaces(&cur); virSkipSpaces(&cur);
if (eol && VIR_STRNDUP(def->serial, cur, eol - cur) < 0) if (eol)
goto cleanup; def->serial = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "machine")) != NULL) { if ((cur = strstr(base, "machine")) != NULL) {
cur = strchr(cur, ':') + 1; cur = strchr(cur, ':') + 1;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpaces(&cur); virSkipSpaces(&cur);
if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0) if (eol)
goto cleanup; def->version = g_strndup(cur, eol - cur);
} }
if (!def->manufacturer && !def->product && !def->version && if (!def->manufacturer && !def->product && !def->version &&
@ -382,7 +379,6 @@ virSysinfoParseARMSystem(const char *base, virSysinfoSystemDefPtr *sysdef)
*sysdef = def; *sysdef = def;
def = NULL; def = NULL;
ret = 0; ret = 0;
cleanup:
virSysinfoSystemDefFree(def); virSysinfoSystemDefFree(def);
return ret; return ret;
} }
@ -402,8 +398,8 @@ virSysinfoParseARMProcessor(const char *base, virSysinfoDefPtr ret)
eol = strchr(tmp_base, '\n'); eol = strchr(tmp_base, '\n');
cur = strchr(tmp_base, ':') + 1; cur = strchr(tmp_base, ':') + 1;
virSkipSpaces(&cur); virSkipSpaces(&cur);
if (eol && VIR_STRNDUP(processor_type, cur, eol - cur) < 0) if (eol)
goto error; processor_type = g_strndup(cur, eol - cur);
while ((tmp_base = strstr(base, "processor")) != NULL) { while ((tmp_base = strstr(base, "processor")) != NULL) {
base = tmp_base; base = tmp_base;
@ -415,10 +411,9 @@ virSysinfoParseARMProcessor(const char *base, virSysinfoDefPtr ret)
processor = &ret->processor[ret->nprocessor - 1]; processor = &ret->processor[ret->nprocessor - 1];
virSkipSpaces(&cur); virSkipSpaces(&cur);
if (eol && if (eol)
VIR_STRNDUP(processor->processor_socket_destination, processor->processor_socket_destination = g_strndup(cur,
cur, eol - cur) < 0) eol - cur);
goto error;
processor->processor_type = g_strdup(processor_type); processor->processor_type = g_strdup(processor_type);
@ -670,29 +665,29 @@ virSysinfoParseBIOS(const char *base, virSysinfoBIOSDefPtr *bios)
cur += 8; cur += 8;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->vendor, cur, eol - cur) < 0) if (eol)
goto cleanup; def->vendor = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "Version: ")) != NULL) { if ((cur = strstr(base, "Version: ")) != NULL) {
cur += 9; cur += 9;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0) if (eol)
goto cleanup; def->version = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "Release Date: ")) != NULL) { if ((cur = strstr(base, "Release Date: ")) != NULL) {
cur += 14; cur += 14;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->date, cur, eol - cur) < 0) if (eol)
goto cleanup; def->date = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "BIOS Revision: ")) != NULL) { if ((cur = strstr(base, "BIOS Revision: ")) != NULL) {
cur += 15; cur += 15;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->release, cur, eol - cur) < 0) if (eol)
goto cleanup; def->release = g_strndup(cur, eol - cur);
} }
if (!def->vendor && !def->version && if (!def->vendor && !def->version &&
@ -704,7 +699,6 @@ virSysinfoParseBIOS(const char *base, virSysinfoBIOSDefPtr *bios)
*bios = def; *bios = def;
def = NULL; def = NULL;
ret = 0; ret = 0;
cleanup:
virSysinfoBIOSDefFree(def); virSysinfoBIOSDefFree(def);
return ret; return ret;
} }
@ -728,50 +722,50 @@ virSysinfoParseX86System(const char *base, virSysinfoSystemDefPtr *sysdef)
cur += 14; cur += 14;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->manufacturer, cur, eol - cur) < 0) if (eol)
goto cleanup; def->manufacturer = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "Product Name: ")) != NULL) { if ((cur = strstr(base, "Product Name: ")) != NULL) {
cur += 14; cur += 14;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->product, cur, eol - cur) < 0) if (eol)
goto cleanup; def->product = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "Version: ")) != NULL) { if ((cur = strstr(base, "Version: ")) != NULL) {
cur += 9; cur += 9;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0) if (eol)
goto cleanup; def->version = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "Serial Number: ")) != NULL) { if ((cur = strstr(base, "Serial Number: ")) != NULL) {
cur += 15; cur += 15;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->serial, cur, eol - cur) < 0) if (eol)
goto cleanup; def->serial = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "UUID: ")) != NULL) { if ((cur = strstr(base, "UUID: ")) != NULL) {
cur += 6; cur += 6;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->uuid, cur, eol - cur) < 0) if (eol)
goto cleanup; def->uuid = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "SKU Number: ")) != NULL) { if ((cur = strstr(base, "SKU Number: ")) != NULL) {
cur += 12; cur += 12;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->sku, cur, eol - cur) < 0) if (eol)
goto cleanup; def->sku = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "Family: ")) != NULL) { if ((cur = strstr(base, "Family: ")) != NULL) {
cur += 8; cur += 8;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->family, cur, eol - cur) < 0) if (eol)
goto cleanup; def->family = g_strndup(cur, eol - cur);
} }
if (!def->manufacturer && !def->product && !def->version && if (!def->manufacturer && !def->product && !def->version &&
@ -783,7 +777,6 @@ virSysinfoParseX86System(const char *base, virSysinfoSystemDefPtr *sysdef)
*sysdef = def; *sysdef = def;
def = NULL; def = NULL;
ret = 0; ret = 0;
cleanup:
virSysinfoSystemDefFree(def); virSysinfoSystemDefFree(def);
return ret; return ret;
} }
@ -813,43 +806,43 @@ virSysinfoParseX86BaseBoard(const char *base,
cur += 14; cur += 14;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->manufacturer, cur, eol - cur) < 0) if (eol)
goto cleanup; def->manufacturer = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "Product Name: ")) != NULL) { if ((cur = strstr(base, "Product Name: ")) != NULL) {
cur += 14; cur += 14;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->product, cur, eol - cur) < 0) if (eol)
goto cleanup; def->product = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "Version: ")) != NULL) { if ((cur = strstr(base, "Version: ")) != NULL) {
cur += 9; cur += 9;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0) if (eol)
goto cleanup; def->version = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "Serial Number: ")) != NULL) { if ((cur = strstr(base, "Serial Number: ")) != NULL) {
cur += 15; cur += 15;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->serial, cur, eol - cur) < 0) if (eol)
goto cleanup; def->serial = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "Asset Tag: ")) != NULL) { if ((cur = strstr(base, "Asset Tag: ")) != NULL) {
cur += 11; cur += 11;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->asset, cur, eol - cur) < 0) if (eol)
goto cleanup; def->asset = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "Location In Chassis: ")) != NULL) { if ((cur = strstr(base, "Location In Chassis: ")) != NULL) {
cur += 21; cur += 21;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->location, cur, eol - cur) < 0) if (eol)
goto cleanup; def->location = g_strndup(cur, eol - cur);
} }
if (!def->manufacturer && !def->product && !def->version && if (!def->manufacturer && !def->product && !def->version &&
@ -898,36 +891,36 @@ virSysinfoParseX86Chassis(const char *base,
cur += 14; cur += 14;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->manufacturer, cur, eol - cur) < 0) if (eol)
goto cleanup; def->manufacturer = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "Version: ")) != NULL) { if ((cur = strstr(base, "Version: ")) != NULL) {
cur += 9; cur += 9;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0) if (eol)
goto cleanup; def->version = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "Serial Number: ")) != NULL) { if ((cur = strstr(base, "Serial Number: ")) != NULL) {
cur += 15; cur += 15;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->serial, cur, eol - cur) < 0) if (eol)
goto cleanup; def->serial = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "Asset Tag: ")) != NULL) { if ((cur = strstr(base, "Asset Tag: ")) != NULL) {
cur += 11; cur += 11;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->asset, cur, eol - cur) < 0) if (eol)
goto cleanup; def->asset = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "SKU Number: ")) != NULL) { if ((cur = strstr(base, "SKU Number: ")) != NULL) {
cur += 12; cur += 12;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->sku, cur, eol - cur) < 0) if (eol)
goto cleanup; def->sku = g_strndup(cur, eol - cur);
} }
if (!def->manufacturer && !def->version && if (!def->manufacturer && !def->version &&
@ -939,7 +932,6 @@ virSysinfoParseX86Chassis(const char *base,
*chassisdef = def; *chassisdef = def;
def = NULL; def = NULL;
ret = 0; ret = 0;
cleanup:
virSysinfoChassisDefFree(def); virSysinfoChassisDefFree(def);
return ret; return ret;
} }
@ -964,86 +956,80 @@ virSysinfoParseX86Processor(const char *base, virSysinfoDefPtr ret)
cur += 20; cur += 20;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(processor->processor_socket_destination, if (eol)
cur, eol - cur) < 0) processor->processor_socket_destination = g_strndup(cur,
return -1; eol - cur);
} }
if ((cur = strstr(base, "Type: ")) != NULL) { if ((cur = strstr(base, "Type: ")) != NULL) {
cur += 6; cur += 6;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(processor->processor_type, cur, eol - cur) < 0) if (eol)
return -1; processor->processor_type = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "Family: ")) != NULL) { if ((cur = strstr(base, "Family: ")) != NULL) {
cur += 8; cur += 8;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(processor->processor_family, cur, eol - cur) < 0) if (eol)
return -1; processor->processor_family = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "Manufacturer: ")) != NULL) { if ((cur = strstr(base, "Manufacturer: ")) != NULL) {
cur += 14; cur += 14;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(processor->processor_manufacturer, if (eol)
cur, eol - cur) < 0) processor->processor_manufacturer = g_strndup(cur, eol - cur);
return -1;
} }
if ((cur = strstr(base, "Signature: ")) != NULL) { if ((cur = strstr(base, "Signature: ")) != NULL) {
cur += 11; cur += 11;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(processor->processor_signature, if (eol)
cur, eol - cur) < 0) processor->processor_signature = g_strndup(cur, eol - cur);
return -1;
} }
if ((cur = strstr(base, "Version: ")) != NULL) { if ((cur = strstr(base, "Version: ")) != NULL) {
cur += 9; cur += 9;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(processor->processor_version, if (eol)
cur, eol - cur) < 0) processor->processor_version = g_strndup(cur, eol - cur);
return -1;
} }
if ((cur = strstr(base, "External Clock: ")) != NULL) { if ((cur = strstr(base, "External Clock: ")) != NULL) {
cur += 16; cur += 16;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(processor->processor_external_clock, if (eol)
cur, eol - cur) < 0) processor->processor_external_clock = g_strndup(cur,
return -1; eol - cur);
} }
if ((cur = strstr(base, "Max Speed: ")) != NULL) { if ((cur = strstr(base, "Max Speed: ")) != NULL) {
cur += 11; cur += 11;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(processor->processor_max_speed, if (eol)
cur, eol - cur) < 0) processor->processor_max_speed = g_strndup(cur, eol - cur);
return -1;
} }
if ((cur = strstr(base, "Status: ")) != NULL) { if ((cur = strstr(base, "Status: ")) != NULL) {
cur += 8; cur += 8;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(processor->processor_status, cur, eol - cur) < 0) if (eol)
return -1; processor->processor_status = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "Serial Number: ")) != NULL) { if ((cur = strstr(base, "Serial Number: ")) != NULL) {
cur += 15; cur += 15;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(processor->processor_serial_number, if (eol)
cur, eol - cur) < 0) processor->processor_serial_number = g_strndup(cur, eol - cur);
return -1;
} }
if ((cur = strstr(base, "Part Number: ")) != NULL) { if ((cur = strstr(base, "Part Number: ")) != NULL) {
cur += 13; cur += 13;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(processor->processor_part_number, if (eol)
cur, eol - cur) < 0) processor->processor_part_number = g_strndup(cur, eol - cur);
return -1;
} }
base += strlen("Processor Information"); base += strlen("Processor Information");
@ -1074,74 +1060,71 @@ virSysinfoParseX86Memory(const char *base, virSysinfoDefPtr ret)
goto next; goto next;
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(memory->memory_size, cur, eol - cur) < 0) if (eol)
return -1; memory->memory_size = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "Form Factor: ")) != NULL) { if ((cur = strstr(base, "Form Factor: ")) != NULL) {
cur += 13; cur += 13;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(memory->memory_form_factor, if (eol)
cur, eol - cur) < 0) memory->memory_form_factor = g_strndup(cur, eol - cur);
return -1;
} }
if ((cur = strstr(base, "Locator: ")) != NULL) { if ((cur = strstr(base, "Locator: ")) != NULL) {
cur += 9; cur += 9;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(memory->memory_locator, cur, eol - cur) < 0) if (eol)
return -1; memory->memory_locator = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "Bank Locator: ")) != NULL) { if ((cur = strstr(base, "Bank Locator: ")) != NULL) {
cur += 14; cur += 14;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(memory->memory_bank_locator, if (eol)
cur, eol - cur) < 0) memory->memory_bank_locator = g_strndup(cur, eol - cur);
return -1;
} }
if ((cur = strstr(base, "Type: ")) != NULL) { if ((cur = strstr(base, "Type: ")) != NULL) {
cur += 6; cur += 6;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(memory->memory_type, cur, eol - cur) < 0) if (eol)
return -1; memory->memory_type = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "Type Detail: ")) != NULL) { if ((cur = strstr(base, "Type Detail: ")) != NULL) {
cur += 13; cur += 13;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(memory->memory_type_detail, cur, eol - cur) < 0) if (eol)
return -1; memory->memory_type_detail = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "Speed: ")) != NULL) { if ((cur = strstr(base, "Speed: ")) != NULL) {
cur += 7; cur += 7;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(memory->memory_speed, cur, eol - cur) < 0) if (eol)
return -1; memory->memory_speed = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "Manufacturer: ")) != NULL) { if ((cur = strstr(base, "Manufacturer: ")) != NULL) {
cur += 14; cur += 14;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(memory->memory_manufacturer, cur, eol - cur) < 0) if (eol)
return -1; memory->memory_manufacturer = g_strndup(cur, eol - cur);
} }
if ((cur = strstr(base, "Serial Number: ")) != NULL) { if ((cur = strstr(base, "Serial Number: ")) != NULL) {
cur += 15; cur += 15;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(memory->memory_serial_number, if (eol)
cur, eol - cur) < 0) memory->memory_serial_number = g_strndup(cur, eol - cur);
return -1;
} }
if ((cur = strstr(base, "Part Number: ")) != NULL) { if ((cur = strstr(base, "Part Number: ")) != NULL) {
cur += 13; cur += 13;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol); virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(memory->memory_part_number, cur, eol - cur) < 0) if (eol)
return -1; memory->memory_part_number = g_strndup(cur, eol - cur);
} }
next: next: