mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
cleanup: unify NULL custom check
Unify testing of NULL custom pointer. Resolve 'factor' only in required if() branch.
This commit is contained in:
parent
cad3568def
commit
121341e52c
@ -3211,7 +3211,9 @@ static const char *_tok_value(struct dm_report *rh,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case DM_REPORT_FIELD_TYPE_STRING_LIST:
|
case DM_REPORT_FIELD_TYPE_STRING_LIST:
|
||||||
str_list = (struct selection_str_list **) custom;
|
if (!(str_list = (struct selection_str_list **) custom))
|
||||||
|
goto_bad;
|
||||||
|
|
||||||
s = _tok_value_string_list(ft, mem, s, begin, end, str_list);
|
s = _tok_value_string_list(ft, mem, s, begin, end, str_list);
|
||||||
if (!(*str_list)) {
|
if (!(*str_list)) {
|
||||||
log_error("Failed to parse string list value "
|
log_error("Failed to parse string list value "
|
||||||
@ -3232,8 +3234,6 @@ static const char *_tok_value(struct dm_report *rh,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
factor = (uint64_t *) custom;
|
|
||||||
|
|
||||||
if (*s == DM_PERCENT_CHAR) {
|
if (*s == DM_PERCENT_CHAR) {
|
||||||
s++;
|
s++;
|
||||||
c = DM_PERCENT_CHAR;
|
c = DM_PERCENT_CHAR;
|
||||||
@ -3244,24 +3244,29 @@ static const char *_tok_value(struct dm_report *rh,
|
|||||||
"numeric" : "size", ft->id);
|
"numeric" : "size", ft->id);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else if ((*factor = dm_units_to_factor(s, &c, 0, &tmp))) {
|
} else {
|
||||||
s = tmp;
|
if (!(factor = (uint64_t *) custom))
|
||||||
if (expected_type != DM_REPORT_FIELD_TYPE_SIZE) {
|
goto_bad;
|
||||||
log_error("Found size unit specifier "
|
|
||||||
"but %s value expected for "
|
if ((*factor = dm_units_to_factor(s, &c, 0, &tmp))) {
|
||||||
"selection field %s.",
|
s = tmp;
|
||||||
expected_type == DM_REPORT_FIELD_TYPE_NUMBER ?
|
if (expected_type != DM_REPORT_FIELD_TYPE_SIZE) {
|
||||||
"numeric" : "percent", ft->id);
|
log_error("Found size unit specifier "
|
||||||
return NULL;
|
"but %s value expected for "
|
||||||
|
"selection field %s.",
|
||||||
|
expected_type == DM_REPORT_FIELD_TYPE_NUMBER ?
|
||||||
|
"numeric" : "percent", ft->id);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
} else if (expected_type == DM_REPORT_FIELD_TYPE_SIZE) {
|
||||||
|
/*
|
||||||
|
* If size unit is not defined in the selection
|
||||||
|
* and the type expected is size, use use 'm'
|
||||||
|
* (1 MiB) for the unit by default. This is the
|
||||||
|
* same behaviour as seen in lvcreate -L <size>.
|
||||||
|
*/
|
||||||
|
*factor = 1024*1024;
|
||||||
}
|
}
|
||||||
} else if (expected_type == DM_REPORT_FIELD_TYPE_SIZE) {
|
|
||||||
/*
|
|
||||||
* If size unit is not defined in the selection
|
|
||||||
* and the type expected is size, use use 'm'
|
|
||||||
* (1 MiB) for the unit by default. This is the
|
|
||||||
* same behaviour as seen in lvcreate -L <size>.
|
|
||||||
*/
|
|
||||||
*factor = 1024*1024;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*flags |= expected_type;
|
*flags |= expected_type;
|
||||||
@ -3273,7 +3278,9 @@ static const char *_tok_value(struct dm_report *rh,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case DM_REPORT_FIELD_TYPE_TIME:
|
case DM_REPORT_FIELD_TYPE_TIME:
|
||||||
tval = (struct time_value *) custom;
|
if (!(tval = (struct time_value *) custom))
|
||||||
|
goto_bad;
|
||||||
|
|
||||||
if (!(s = _tok_value_time(ft, mem, s, begin, end, tval))) {
|
if (!(s = _tok_value_time(ft, mem, s, begin, end, tval))) {
|
||||||
log_error("Failed to parse time value "
|
log_error("Failed to parse time value "
|
||||||
"for selection field %s.", ft->id);
|
"for selection field %s.", ft->id);
|
||||||
@ -3290,6 +3297,10 @@ static const char *_tok_value(struct dm_report *rh,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
|
bad:
|
||||||
|
log_error(INTERNAL_ERROR "Forbidden NULL custom detected.");
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -3412,7 +3423,8 @@ static struct field_selection *_create_field_selection(struct dm_report *rh,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (((rvw->reserved && (rvw->reserved->type & DM_REPORT_FIELD_RESERVED_VALUE_RANGE)) ||
|
if (((rvw->reserved && (rvw->reserved->type & DM_REPORT_FIELD_RESERVED_VALUE_RANGE)) ||
|
||||||
(((flags & DM_REPORT_FIELD_TYPE_MASK) == DM_REPORT_FIELD_TYPE_TIME) && ((struct time_value *) custom)->range))
|
(((flags & DM_REPORT_FIELD_TYPE_MASK) == DM_REPORT_FIELD_TYPE_TIME) &&
|
||||||
|
custom && ((struct time_value *) custom)->range))
|
||||||
&&
|
&&
|
||||||
!(fs->value->next = dm_pool_zalloc(rh->selection->mem, sizeof(struct field_selection_value)))) {
|
!(fs->value->next = dm_pool_zalloc(rh->selection->mem, sizeof(struct field_selection_value)))) {
|
||||||
log_error(_field_selection_value_alloc_failed_msg, field_id);
|
log_error(_field_selection_value_alloc_failed_msg, field_id);
|
||||||
@ -3529,10 +3541,8 @@ static struct field_selection *_create_field_selection(struct dm_report *rh,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DM_REPORT_FIELD_TYPE_STRING_LIST:
|
case DM_REPORT_FIELD_TYPE_STRING_LIST:
|
||||||
if (!custom) {
|
if (!custom)
|
||||||
log_error(INTERNAL_ERROR "Custom selection list is undefined.");
|
goto_bad;
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
fs->value->v.l = *(struct selection_str_list **)custom;
|
fs->value->v.l = *(struct selection_str_list **)custom;
|
||||||
if (_check_value_is_strictly_reserved(rh, field_num, DM_REPORT_FIELD_TYPE_STRING_LIST, fs->value->v.l, NULL)) {
|
if (_check_value_is_strictly_reserved(rh, field_num, DM_REPORT_FIELD_TYPE_STRING_LIST, fs->value->v.l, NULL)) {
|
||||||
log_error("String list value found in selection is reserved.");
|
log_error("String list value found in selection is reserved.");
|
||||||
@ -3545,11 +3555,8 @@ static struct field_selection *_create_field_selection(struct dm_report *rh,
|
|||||||
if (rvw->reserved->type & DM_REPORT_FIELD_RESERVED_VALUE_RANGE)
|
if (rvw->reserved->type & DM_REPORT_FIELD_RESERVED_VALUE_RANGE)
|
||||||
fs->value->next->v.t = (((const time_t *) rvw->value)[1]);
|
fs->value->next->v.t = (((const time_t *) rvw->value)[1]);
|
||||||
} else {
|
} else {
|
||||||
if (!custom) {
|
if (!(tval = (struct time_value *) custom))
|
||||||
log_error(INTERNAL_ERROR "Custom time value is undefined.");
|
goto_bad;
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
tval = (struct time_value *) custom;
|
|
||||||
fs->value->v.t = tval->t1;
|
fs->value->v.t = tval->t1;
|
||||||
if (tval->range)
|
if (tval->range)
|
||||||
fs->value->next->v.t = tval->t2;
|
fs->value->next->v.t = tval->t2;
|
||||||
@ -3567,8 +3574,11 @@ static struct field_selection *_create_field_selection(struct dm_report *rh,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return fs;
|
return fs;
|
||||||
|
bad:
|
||||||
|
log_error(INTERNAL_ERROR "Forbiden NULL custom detected.");
|
||||||
error:
|
error:
|
||||||
dm_pool_free(rh->selection->mem, fs);
|
dm_pool_free(rh->selection->mem, fs);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user