mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
coverity: fix some issues reported by coverity for recent code
This commit is contained in:
parent
3d26d283ea
commit
94f78e0183
@ -366,6 +366,7 @@ static int _get_sysfs_value(const char *path, char *buf, size_t buf_size)
|
|||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
int r = 0;
|
||||||
|
|
||||||
if (!(fp = fopen(path, "r"))) {
|
if (!(fp = fopen(path, "r"))) {
|
||||||
log_sys_error("fopen", path);
|
log_sys_error("fopen", path);
|
||||||
@ -374,23 +375,23 @@ static int _get_sysfs_value(const char *path, char *buf, size_t buf_size)
|
|||||||
|
|
||||||
if (!fgets(buf, buf_size, fp)) {
|
if (!fgets(buf, buf_size, fp)) {
|
||||||
log_sys_error("fgets", path);
|
log_sys_error("fgets", path);
|
||||||
if (fclose(fp))
|
goto out;
|
||||||
log_sys_error("fclose", path);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(len = strlen(buf)) || (len == 1 && buf[0] == '\n')) {
|
if (!(len = strlen(buf)) || (len == 1 && buf[0] == '\n')) {
|
||||||
log_error("_get_sysfs_value: %s: no value", path);
|
log_error("_get_sysfs_value: %s: no value", path);
|
||||||
return 0;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[len - 1] == '\n')
|
if (buf[len - 1] == '\n')
|
||||||
buf[len - 1] = '\0';
|
buf[len - 1] = '\0';
|
||||||
|
|
||||||
|
r = 1;
|
||||||
|
out:
|
||||||
if (fclose(fp))
|
if (fclose(fp))
|
||||||
log_sys_error("fclose", path);
|
log_sys_error("fclose", path);
|
||||||
|
|
||||||
return 1;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _get_dm_uuid_from_sysfs(char *buf, size_t buf_size, int major, int minor)
|
static int _get_dm_uuid_from_sysfs(char *buf, size_t buf_size, int major, int minor)
|
||||||
@ -427,14 +428,14 @@ static struct dm_list *_get_or_add_list_by_index_key(struct dm_hash_table *idx,
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct device *_get_device_for_sysfs_dev_name_using_devno(const char *dev_name)
|
static struct device *_get_device_for_sysfs_dev_name_using_devno(const char *devname)
|
||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
int major, minor;
|
int major, minor;
|
||||||
|
|
||||||
if (dm_snprintf(path, sizeof(path), "%sblock/%s/dev", dm_sysfs_dir(), dev_name) < 0) {
|
if (dm_snprintf(path, sizeof(path), "%sblock/%s/dev", dm_sysfs_dir(), devname) < 0) {
|
||||||
log_error("_get_device_for_non_dm_dev: %s: dm_snprintf failed", dev_name);
|
log_error("_get_device_for_non_dm_dev: %s: dm_snprintf failed", devname);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -442,7 +443,7 @@ static struct device *_get_device_for_sysfs_dev_name_using_devno(const char *dev
|
|||||||
return_NULL;
|
return_NULL;
|
||||||
|
|
||||||
if (sscanf(buf, "%d:%d", &major, &minor) != 2) {
|
if (sscanf(buf, "%d:%d", &major, &minor) != 2) {
|
||||||
log_error("_get_device_for_non_dm_dev: %s: failed to get major and minor number", dev_name);
|
log_error("_get_device_for_non_dm_dev: %s: failed to get major and minor number", devname);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4600,8 +4600,10 @@ static int _check_devs_used_correspond_with_lv(struct dm_pool *mem, struct dm_li
|
|||||||
if (!found_inconsistent) {
|
if (!found_inconsistent) {
|
||||||
dm_pool_begin_object(mem, 32);
|
dm_pool_begin_object(mem, 32);
|
||||||
found_inconsistent = 1;
|
found_inconsistent = 1;
|
||||||
} else
|
} else {
|
||||||
dm_pool_grow_object(mem, DEV_LIST_DELIM, sizeof(DEV_LIST_DELIM) - 1);
|
if (!dm_pool_grow_object(mem, DEV_LIST_DELIM, sizeof(DEV_LIST_DELIM) - 1))
|
||||||
|
goto_bad;
|
||||||
|
}
|
||||||
if (!dm_pool_grow_object(mem, dev_name(dev), 0))
|
if (!dm_pool_grow_object(mem, dev_name(dev), 0))
|
||||||
goto_bad;
|
goto_bad;
|
||||||
}
|
}
|
||||||
@ -4610,7 +4612,8 @@ static int _check_devs_used_correspond_with_lv(struct dm_pool *mem, struct dm_li
|
|||||||
if (!found_inconsistent)
|
if (!found_inconsistent)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
dm_pool_grow_object(mem, "\0", 1);
|
if (!dm_pool_grow_object(mem, "\0", 1))
|
||||||
|
goto_bad;
|
||||||
used_devnames = dm_pool_end_object(mem);
|
used_devnames = dm_pool_end_object(mem);
|
||||||
|
|
||||||
found_inconsistent = 0;
|
found_inconsistent = 0;
|
||||||
@ -4628,7 +4631,8 @@ static int _check_devs_used_correspond_with_lv(struct dm_pool *mem, struct dm_li
|
|||||||
dm_pool_begin_object(mem, 32);
|
dm_pool_begin_object(mem, 32);
|
||||||
found_inconsistent = 1;
|
found_inconsistent = 1;
|
||||||
} else {
|
} else {
|
||||||
dm_pool_grow_object(mem, DEV_LIST_DELIM, sizeof(DEV_LIST_DELIM) - 1);
|
if (!dm_pool_grow_object(mem, DEV_LIST_DELIM, sizeof(DEV_LIST_DELIM) - 1))
|
||||||
|
goto_bad;
|
||||||
}
|
}
|
||||||
if (!dm_pool_grow_object(mem, dev_name(dev), 0))
|
if (!dm_pool_grow_object(mem, dev_name(dev), 0))
|
||||||
goto bad;
|
goto bad;
|
||||||
@ -4638,7 +4642,8 @@ static int _check_devs_used_correspond_with_lv(struct dm_pool *mem, struct dm_li
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (found_inconsistent) {
|
if (found_inconsistent) {
|
||||||
dm_pool_grow_object(mem, "\0", 1);
|
if (!dm_pool_grow_object(mem, "\0", 1))
|
||||||
|
goto_bad;
|
||||||
assumed_devnames = dm_pool_end_object(mem);
|
assumed_devnames = dm_pool_end_object(mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user