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@xxxxxxxxxx> --- src/conf/domain_conf.c | 19 +++++-------------- .../machine-loadparm-s390-char-invalid.err | 2 +- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c542782750..b1cc229d97 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -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; diff --git a/tests/qemuxml2argvdata/machine-loadparm-s390-char-invalid.err b/tests/qemuxml2argvdata/machine-loadparm-s390-char-invalid.err index c3eb455594..0283db9f48 100644 --- a/tests/qemuxml2argvdata/machine-loadparm-s390-char-invalid.err +++ b/tests/qemuxml2argvdata/machine-loadparm-s390-char-invalid.err @@ -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 -- 2.31.1