提交 549b8399 编写于 作者: E Eric Blake

storage: kill dead stores

Found by clang.  Clang complained that virStorageBackendProbeTarget
could dereference NULL if backingStoreFormat was NULL, but since all
callers passed a valid pointer, I added attributes instead of null
checks.

* src/storage/storage_backend.c
(virStorageBackendQEMUImgBackingFormat): Kill dead store.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget):
Likewise.  Skip null checks, by adding attributes.
上级 68e4be71
......@@ -581,7 +581,6 @@ static int virStorageBackendQEMUImgBackingFormat(const char *qemuimg)
int newstdout = -1;
char *help = NULL;
enum { MAX_HELP_OUTPUT_SIZE = 1024*8 };
int len;
char *start;
char *end;
char *tmp;
......@@ -591,7 +590,7 @@ static int virStorageBackendQEMUImgBackingFormat(const char *qemuimg)
&child, -1, &newstdout, NULL, VIR_EXEC_CLEAR_CAPS) < 0)
goto cleanup;
if ((len = virFileReadLimFD(newstdout, MAX_HELP_OUTPUT_SIZE, &help)) < 0) {
if (virFileReadLimFD(newstdout, MAX_HELP_OUTPUT_SIZE, &help) < 0) {
virReportSystemError(errno,
_("Unable to read '%s -h' output"),
qemuimg);
......
......@@ -48,7 +48,7 @@
#define VIR_FROM_THIS VIR_FROM_STORAGE
static int
static int ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
virStorageBackendProbeTarget(virStorageVolTargetPtr target,
char **backingStore,
int *backingStoreFormat,
......@@ -59,10 +59,8 @@ virStorageBackendProbeTarget(virStorageVolTargetPtr target,
int fd, ret;
virStorageFileMetadata meta;
if (backingStore)
*backingStore = NULL;
if (backingStoreFormat)
*backingStoreFormat = VIR_STORAGE_FILE_AUTO;
*backingStore = NULL;
*backingStoreFormat = VIR_STORAGE_FILE_AUTO;
if (encryption)
*encryption = NULL;
......@@ -75,7 +73,7 @@ virStorageBackendProbeTarget(virStorageVolTargetPtr target,
allocation,
capacity)) < 0) {
close(fd);
return -1;
return ret;
}
memset(&meta, 0, sizeof(meta));
......@@ -95,20 +93,19 @@ virStorageBackendProbeTarget(virStorageVolTargetPtr target,
close(fd);
if (meta.backingStore) {
if (backingStore) {
*backingStore = meta.backingStore;
meta.backingStore = NULL;
if (meta.backingStoreFormat == VIR_STORAGE_FILE_AUTO) {
if ((*backingStoreFormat = virStorageFileProbeFormat(*backingStore)) < 0) {
close(fd);
goto cleanup;
}
} else {
*backingStoreFormat = meta.backingStoreFormat;
*backingStore = meta.backingStore;
meta.backingStore = NULL;
if (meta.backingStoreFormat == VIR_STORAGE_FILE_AUTO) {
if ((*backingStoreFormat
= virStorageFileProbeFormat(*backingStore)) < 0) {
close(fd);
goto cleanup;
}
} else {
VIR_FREE(meta.backingStore);
*backingStoreFormat = meta.backingStoreFormat;
}
} else {
VIR_FREE(meta.backingStore);
}
if (capacity && meta.capacity)
......@@ -139,8 +136,7 @@ virStorageBackendProbeTarget(virStorageVolTargetPtr target,
return 0;
cleanup:
if (backingStore)
VIR_FREE(*backingStore);
VIR_FREE(*backingStore);
return -1;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册