1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

more coverity fixes

This commit is contained in:
Alasdair Kergon 2006-05-10 17:49:25 +00:00
parent eba586f053
commit 2c7fbadeef
11 changed files with 51 additions and 25 deletions

View File

@ -123,7 +123,10 @@ const struct format_type *fmt_from_vgname(const char *vgname, const char *vgid)
* we check cached labels here. Unfortunately vginfo is volatile. */
list_init(&devs);
list_iterate_items(info, &vginfo->infos) {
devl = dm_malloc(sizeof(*devl));
if (!(devl = dm_malloc(sizeof(*devl)))) {
log_error("device_list element allocation failed");
return NULL;
}
devl->dev = info->dev;
list_add(&devs, &devl->list);
}

View File

@ -952,7 +952,7 @@ struct cmd_context *create_toolcontext(struct arg *the_args)
if (!(cmd->mem = dm_pool_create("command", 4 * 1024))) {
log_error("Command memory pool creation failed");
return 0;
goto error;
}
memlock_init(cmd);

View File

@ -688,14 +688,20 @@ static void _eat_space(struct parser *p)
static struct config_value *_create_value(struct parser *p)
{
struct config_value *v = dm_pool_alloc(p->mem, sizeof(*v));
memset(v, 0, sizeof(*v));
if (v)
memset(v, 0, sizeof(*v));
return v;
}
static struct config_node *_create_node(struct parser *p)
{
struct config_node *n = dm_pool_alloc(p->mem, sizeof(*n));
memset(n, 0, sizeof(*n));
if (n)
memset(n, 0, sizeof(*n));
return n;
}

View File

@ -124,15 +124,13 @@ int export_pv(struct cmd_context *cmd, struct dm_pool *mem,
memcpy(pvd->pv_uuid, pv->id.uuid, ID_LEN);
if (!_check_vg_name(pv->vg_name)) {
stack;
return 0;
}
memset(pvd->vg_name, 0, sizeof(pvd->vg_name));
if (pv->vg_name)
if (pv->vg_name) {
if (!_check_vg_name(pv->vg_name)) {
stack;
return 0;
}
strncpy((char *)pvd->vg_name, pv->vg_name, sizeof(pvd->vg_name));
}
/* Preserve existing system_id if it exists */
if (vg && *vg->system_id)

View File

@ -44,7 +44,7 @@ const char *text_vgname_import(const struct format_type *fmt,
}
if (!(cft = create_config_tree(NULL)))
goto_out;
return_NULL;
if ((!dev && !read_config_file(cft)) ||
(dev && !read_config_fd(cft, dev, offset, size,
@ -94,10 +94,8 @@ struct volume_group *text_vg_import_fd(struct format_instance *fid,
*desc = NULL;
*when = 0;
if (!(cft = create_config_tree(file))) {
stack;
goto out;
}
if (!(cft = create_config_tree(file)))
return_NULL
if ((!dev && !read_config_file(cft)) ||
(dev && !read_config_fd(cft, dev, offset, size,

View File

@ -386,11 +386,12 @@ int lock_resource(struct cmd_context *cmd, const char *resource, int flags)
int cluster_cmd = 0;
assert(strlen(resource) < sizeof(lockname));
assert(resource);
switch (flags & LCK_SCOPE_MASK) {
case LCK_VG:
/* If the VG name is empty then lock the unused PVs */
if (!resource || !*resource)
if (!*resource)
lvm_snprintf(lockname, sizeof(lockname), "P_orphans");
else
lvm_snprintf(lockname, sizeof(lockname), "V_%s",

View File

@ -207,9 +207,11 @@ static int _file_lock_resource(struct cmd_context *cmd, const char *resource,
{
char lockfile[PATH_MAX];
assert(resource);
switch (flags & LCK_SCOPE_MASK) {
case LCK_VG:
if (!resource || !*resource)
if (!*resource)
lvm_snprintf(lockfile, sizeof(lockfile),
"%s/P_orphans", _lock_dir);
else

View File

@ -266,7 +266,10 @@ struct volume_group *vg_create(struct cmd_context *cmd, const char *vg_name,
vg->seqno = 0;
vg->status = (RESIZEABLE_VG | LVM_READ | LVM_WRITE);
vg->system_id = dm_pool_alloc(mem, NAME_LEN);
if (!(vg->system_id = dm_pool_alloc(mem, NAME_LEN))) {
stack;
goto bad;
}
*vg->system_id = '\0';
vg->extent_size = extent_size;

View File

@ -214,8 +214,11 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
return 0;
}
if (*opts == '+') {
str = dm_pool_alloc(cmd->mem,
strlen(options) + strlen(opts) + 1);
if (!(str = dm_pool_alloc(cmd->mem,
strlen(options) + strlen(opts) + 1))) {
log_error("options string allocation failed");
return 0;
}
strcpy(str, options);
strcat(str, ",");
strcat(str, opts + 1);

View File

@ -405,7 +405,11 @@ static int _process_one_vg(struct cmd_context *cmd, const char *vg_name,
}
log_verbose("Finding volume group \"%s\"", vg_name);
vg = vg_read(cmd, vg_name, vgid, &consistent);
if (!(vg = vg_read(cmd, vg_name, vgid, &consistent))) {
log_error("Volume group \"%s\" not found", vg_name);
unlock_vg(cmd, vg_name);
return ret_max;
}
if (!list_empty(tags)) {
/* Only process if a tag matches or it's on arg_vgnames */
@ -649,7 +653,11 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv,
if (!list_empty(&tags) && (vgnames = get_vgs(cmd, 0)) &&
!list_empty(vgnames)) {
list_iterate_items(sll, vgnames) {
vg = vg_read(cmd, sll->str, NULL, &consistent);
if (!(vg = vg_read(cmd, sll->str, NULL, &consistent))) {
log_error("Volume group \"%s\" not found", sll->str);
ret_max = ECMD_FAILED;
continue;
}
if (!consistent)
continue;
ret = process_each_pv_in_vg(cmd, vg, &tags,

View File

@ -23,7 +23,11 @@ static char *_expand_filename(const char *template, const char *vg_name,
if (security_level())
return dm_strdup(template);
filename = dm_malloc(PATH_MAX);
if (!(filename = dm_malloc(PATH_MAX))) {
log_error("Failed to allocate filename.");
return NULL;
}
if (snprintf(filename, PATH_MAX, template, vg_name) < 0) {
log_error("Error processing filename template %s",
template);