mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 03:25:20 +00:00
maint: Kill usage of atoi()
Kill the use of atoi() and introduce syntax check to forbid it and it's friends (atol, atoll, atof, atoq). Also fix a typo in variable name holding the cylinders count of a disk pool (apparently unused). examples/domsuspend/suspend.c will need a larger scale refactor as the whole example file is broken thus it will be exempted from the syntax check for now.
This commit is contained in:
parent
5eb4b04211
commit
df36af589f
6
cfg.mk
6
cfg.mk
@ -869,6 +869,12 @@ sc_prohibit_getenv:
|
|||||||
halt='Use virGetEnv{Allow,Block}SUID instead of getenv' \
|
halt='Use virGetEnv{Allow,Block}SUID instead of getenv' \
|
||||||
$(_sc_search_regexp)
|
$(_sc_search_regexp)
|
||||||
|
|
||||||
|
sc_prohibit_atoi:
|
||||||
|
@prohibit='\bato(i|f|l|ll|q) *\(' \
|
||||||
|
halt='Use virStrToLong* instead of atoi, atol, atof, atoq, atoll' \
|
||||||
|
$(_sc_search_regexp)
|
||||||
|
|
||||||
|
|
||||||
# We don't use this feature of maint.mk.
|
# We don't use this feature of maint.mk.
|
||||||
prev_version_file = /dev/null
|
prev_version_file = /dev/null
|
||||||
|
|
||||||
|
@ -229,7 +229,7 @@ struct _virStoragePoolSourceDevice {
|
|||||||
* the geometry data is needed
|
* the geometry data is needed
|
||||||
*/
|
*/
|
||||||
struct _geometry {
|
struct _geometry {
|
||||||
int cyliders;
|
int cylinders;
|
||||||
int heads;
|
int heads;
|
||||||
int sectors;
|
int sectors;
|
||||||
} geometry;
|
} geometry;
|
||||||
|
@ -280,12 +280,16 @@ virStorageBackendDiskMakePoolGeometry(virStoragePoolObjPtr pool,
|
|||||||
char **const groups,
|
char **const groups,
|
||||||
void *data ATTRIBUTE_UNUSED)
|
void *data ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
|
virStoragePoolSourceDevicePtr device = &(pool->def->source.devices[0]);
|
||||||
|
if (virStrToLong_i(groups[0], NULL, 0, &device->geometry.cylinders) < 0 ||
|
||||||
|
virStrToLong_i(groups[1], NULL, 0, &device->geometry.heads) < 0 ||
|
||||||
|
virStrToLong_i(groups[2], NULL, 0, &device->geometry.sectors) < 0) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("Failed to create disk pool geometry"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
pool->def->source.devices[0].geometry.cyliders = atoi(groups[0]);
|
return 0;
|
||||||
pool->def->source.devices[0].geometry.heads = atoi(groups[1]);
|
|
||||||
pool->def->source.devices[0].geometry.sectors = atoi(groups[2]);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -290,10 +290,19 @@ xend_req(int fd, char **content)
|
|||||||
if (STREQ(buffer, "\r\n"))
|
if (STREQ(buffer, "\r\n"))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (istartswith(buffer, "Content-Length: "))
|
if (istartswith(buffer, "Content-Length: ")) {
|
||||||
content_length = atoi(buffer + 16);
|
if (virStrToLong_i(buffer + 16, NULL, 10, &content_length) < 0) {
|
||||||
else if (istartswith(buffer, "HTTP/1.1 "))
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
retcode = atoi(buffer + 9);
|
_("failed to parse Xend response content length"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else if (istartswith(buffer, "HTTP/1.1 ")) {
|
||||||
|
if (virStrToLong_i(buffer + 9, NULL, 10, &retcode) < 0) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("failed to parse Xend response return code"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_FREE(buffer);
|
VIR_FREE(buffer);
|
||||||
|
Loading…
Reference in New Issue
Block a user