virDomainDeviceLoadparmIsValid: Use 'strspn' instead of a loop

In other places we use strspn to validate a character subset. Convert
the in-place loop and simplify the error message.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2021-11-25 13:44:13 +01:00
parent d23389d2b7
commit 55d951ef58
2 changed files with 6 additions and 15 deletions

View File

@ -6298,8 +6298,6 @@ virDomainObjCheckActive(virDomainObj *dom)
static bool
virDomainDeviceLoadparmIsValid(const char *loadparm)
{
size_t i;
if (virStringIsEmpty(loadparm) || !STRLIM(loadparm, 8)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("loadparm value '%s' must be between 1 and 8 characters"),
@ -6307,18 +6305,11 @@ virDomainDeviceLoadparmIsValid(const char *loadparm)
return false;
}
for (i = 0; i < strlen(loadparm); i++) {
uint8_t c = loadparm[i];
if (('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') ||
(c == '.') || (c == ' ')) {
continue;
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("invalid loadparm char '%c', expecting chars"
" in set of [a-zA-Z0-9.] and blank spaces"), c);
return false;
}
if (strspn(loadparm, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789. ") != strlen(loadparm)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("invalid loadparm value '%s', expecting chars in set of [a-zA-Z0-9.] and blank spaces"),
loadparm);
return false;
}
return true;

View File

@ -1 +1 @@
internal error: invalid loadparm char '?', expecting chars in set of [a-zA-Z0-9.] and blank spaces
internal error: invalid loadparm value 'SYS1?', expecting chars in set of [a-zA-Z0-9.] and blank spaces