internal: Introduce virCheckNonEmptyStringArgGoto and reuse it

The helper makes sure that strings passed to APIs are non-NULL and
non-empty. This allows to drop some inlined checks where it does not
make sense.
This commit is contained in:
Peter Krempa 2015-06-23 17:35:16 +02:00
parent d637017f9b
commit 14062e6fe5
4 changed files with 24 additions and 13 deletions

View File

@ -446,6 +446,17 @@
goto label; \
} \
} while (0)
# define virCheckNonEmptyStringArgGoto(argname, label) \
do { \
if (argname == NULL) { \
virReportInvalidNonNullArg(argname); \
goto label; \
} \
if (*argname == '\0') { \
virReportInvalidEmptyStringArg(argname); \
goto label; \
} \
} while (0)
# define virCheckPositiveArgGoto(argname, label) \
do { \
if (argname <= 0) { \

View File

@ -6065,7 +6065,7 @@ virDomainBlockPeek(virDomainPtr dom,
conn = dom->conn;
virCheckReadOnlyGoto(conn->flags, error);
virCheckNonNullArgGoto(disk, error);
virCheckNonEmptyStringArgGoto(disk, error);
/* Allow size == 0 as an access test. */
if (size > 0)
@ -6333,7 +6333,7 @@ virDomainGetBlockInfo(virDomainPtr domain, const char *disk,
memset(info, 0, sizeof(*info));
virCheckDomainReturn(domain, -1);
virCheckNonNullArgGoto(disk, error);
virCheckNonEmptyStringArgGoto(disk, error);
virCheckNonNullArgGoto(info, error);
conn = domain->conn;

View File

@ -11530,12 +11530,6 @@ qemuDomainBlockPeek(virDomainPtr dom,
if (virDomainBlockPeekEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
if (!path || path[0] == '\0') {
virReportError(VIR_ERR_INVALID_ARG,
"%s", _("NULL or empty path"));
goto cleanup;
}
/* Check the path belongs to this domain. */
if (!(actual = virDomainDiskPathByName(vm->def, path))) {
virReportError(VIR_ERR_INVALID_ARG,
@ -11821,11 +11815,6 @@ qemuDomainGetBlockInfo(virDomainPtr dom,
if (virDomainGetBlockInfoEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
if (!path || path[0] == '\0') {
virReportError(VIR_ERR_INVALID_ARG, "%s", _("NULL or empty path"));
goto cleanup;
}
/* Technically, we only need a job if we are going to query the
* monitor, which is only for active domains that are using
* non-raw block devices. But it is easier to share code if we

View File

@ -95,6 +95,17 @@ void virReportSystemErrorFull(int domcode,
0, 0, \
_("%s in %s must not be NULL"), \
#argname, __FUNCTION__)
# define virReportInvalidEmptyStringArg(argname) \
virRaiseErrorFull(__FILE__, __FUNCTION__, __LINE__, \
VIR_FROM_THIS, \
VIR_ERR_INVALID_ARG, \
VIR_ERR_ERROR, \
__FUNCTION__, \
#argname, \
NULL, \
0, 0, \
_("string %s in %s must not be empty"), \
#argname, __FUNCTION__)
# define virReportInvalidPositiveArg(argname) \
virRaiseErrorFull(__FILE__, __FUNCTION__, __LINE__, \
VIR_FROM_THIS, \