Cleanup: avoid shadowing, redundant assignment & minor changes

Quiet cppecheck warnings, use const pointers, ELEM(..) macro,
replace NULL -> nullptr, unsigned int -> uint.
This commit is contained in:
Campbell Barton 2024-07-07 00:03:57 +10:00
parent 7bce839e25
commit 48383cf20e
14 changed files with 25 additions and 23 deletions

@ -1095,7 +1095,7 @@ CombinedKeyingResult insert_keyframes(Main *bmain,
* be tagged for a depsgraph update regardless. This code is here because it
* was part of the function this one was refactored from, but at some point
* this should be investigated and either documented or removed. */
if (adt->action != nullptr && adt->action != action) {
if (!ELEM(adt->action, nullptr, action)) {
DEG_id_tag_update(&adt->action->id, ID_RECALC_ANIMATION_NO_FLUSH);
}
}

@ -346,7 +346,7 @@ int BLF_default_weight(int fontid)
bool BLF_has_variable_weight(int fontid)
{
FontBLF *font = blf_get(fontid);
const FontBLF *font = blf_get(fontid);
if (font && font->variations) {
for (int i = 0; i < int(font->variations->num_axis); i++) {
if (font->variations->axis[i].tag == BLF_VARIATION_AXIS_WEIGHT) {

@ -1682,7 +1682,7 @@ PartialWriteContext::~PartialWriteContext()
BKE_main_destroy(this->bmain);
};
void PartialWriteContext::preempt_session_uid(ID *ctx_id, unsigned int session_uid)
void PartialWriteContext::preempt_session_uid(ID *ctx_id, uint session_uid)
{
/* If there is already an existing ID in the 'matching' set with that UID, it should be the same
* as the given ctx_id. */
@ -1763,7 +1763,7 @@ ID *PartialWriteContext::id_add_copy(const ID *id, const bool regenerate_session
void PartialWriteContext::make_local(ID *ctx_id, const int make_local_flags)
{
/* Making an ID local typically resets its session UID, here we want to keep the same value. */
const unsigned int ctx_id_session_uid = ctx_id->session_uid;
const uint ctx_id_session_uid = ctx_id->session_uid;
BKE_main_idmap_remove_id(this->bmain.id_map, ctx_id);
BKE_main_idmap_insert_id(matching_uid_map_, ctx_id);

@ -892,7 +892,7 @@ bool whitepoint_to_temp_tint(const float3 &white, float &temperature, float &tin
if (entry == planck_locus.begin() || entry == planck_locus.end()) {
return false;
}
const size_t i = (size_t)(entry - planck_locus.begin());
const size_t i = size_t(entry - planck_locus.begin());
const locus_entry_t &low = planck_locus[i - 1], high = planck_locus[i];
/* Find closest point on locus. */
@ -919,7 +919,7 @@ float3 whitepoint_from_temp_tint(const float temperature, const float tint)
1e6f / temperature, planck_locus[0].mired, planck_locus[planck_locus.size() - 1].mired);
auto check = [](const locus_entry_t &entry, const float val) { return entry.mired < val; };
const auto entry = std::lower_bound(planck_locus.begin(), planck_locus.end(), mired, check);
const size_t i = (size_t)(entry - planck_locus.begin());
const size_t i = size_t(entry - planck_locus.begin());
const locus_entry_t &low = planck_locus[i - 1], high = planck_locus[i];
/* Find interpolation factor. */

@ -254,10 +254,10 @@ std::optional<bool> AssetViewItem::should_be_active() const
return matches;
}
bool AssetViewItem::should_be_filtered_visible(const StringRefNull filter_str) const
bool AssetViewItem::should_be_filtered_visible(const StringRefNull filter_string) const
{
const StringRefNull asset_name = handle_get_representation(&asset_)->get_name();
return fnmatch(filter_str.c_str(), asset_name.c_str(), FNM_CASEFOLD) == 0;
return fnmatch(filter_string.c_str(), asset_name.c_str(), FNM_CASEFOLD) == 0;
}
std::unique_ptr<ui::AbstractViewItemDragController> AssetViewItem::create_drag_controller() const

@ -755,7 +755,7 @@ const EnumPropertyItem enum_layergroup_color_items[] = {
{LAYERGROUP_COLOR_06, "COLOR6", ICON_LAYERGROUP_COLOR_06, "Color tag 6", ""},
{LAYERGROUP_COLOR_07, "COLOR7", ICON_LAYERGROUP_COLOR_07, "Color tag 7", ""},
{LAYERGROUP_COLOR_08, "COLOR8", ICON_LAYERGROUP_COLOR_08, "Color tag 8", ""},
{0, NULL, 0, NULL, NULL},
{0, nullptr, 0, nullptr, nullptr},
};
static int grease_pencil_layer_group_color_tag_exec(bContext *C, wmOperator *op)

@ -10887,13 +10887,13 @@ static int ui_handle_menu_event(bContext *C,
}
/* Accelerator keys that allow "pressing" a menu entry by pressing a single key. */
LISTBASE_FOREACH (uiBut *, but, &block->buttons) {
if (!(but->flag & UI_BUT_DISABLED) && but->menu_key == event->type) {
if (but->type == UI_BTYPE_BUT) {
UI_but_execute(C, region, but);
LISTBASE_FOREACH (uiBut *, but_iter, &block->buttons) {
if (!(but_iter->flag & UI_BUT_DISABLED) && but_iter->menu_key == event->type) {
if (but_iter->type == UI_BTYPE_BUT) {
UI_but_execute(C, region, but_iter);
}
else {
ui_handle_button_activate_by_type(C, region, but);
ui_handle_button_activate_by_type(C, region, but_iter);
}
return WM_UI_HANDLER_BREAK;
}

@ -1353,7 +1353,7 @@ static void widget_draw_icon(
/* Get theme color. */
uchar color[4] = {mono_color[0], mono_color[1], mono_color[2], mono_color[3]};
bTheme *btheme = UI_GetTheme();
const bTheme *btheme = UI_GetTheme();
const bool has_theme = UI_icon_get_theme_color(int(icon), color);
const bool outline = btheme->tui.icon_border_intensity > 0.0f && has_theme;
@ -1380,7 +1380,6 @@ static void widget_draw_icon(
but->drawflag & UI_BUT_ICON_INVERT);
}
else {
const bTheme *btheme = UI_GetTheme();
const float desaturate = 1.0 - btheme->tui.icon_saturation;
UI_icon_draw_ex(
xs, ys, icon, aspect, alpha, desaturate, color, outline, &but->icon_overlay_text);

@ -643,14 +643,15 @@ static void file_draw_preview(const FileList *files,
/* Don't show outer document image if loading - too flashy. */
if (is_icon) {
/* Draw large folder or document icon. */
const int icon = (file->typeflag & FILE_TYPE_DIR) ? ICON_FILE_FOLDER_LARGE : ICON_FILE_LARGE;
const int icon_large = (file->typeflag & FILE_TYPE_DIR) ? ICON_FILE_FOLDER_LARGE :
ICON_FILE_LARGE;
uchar icon_col[4];
rgba_float_to_uchar(icon_col, document_img_col);
float icon_x = float(xco) + (file->typeflag & FILE_TYPE_DIR ? 0.0f : ex * -0.142f);
float icon_y = float(yco) + (file->typeflag & FILE_TYPE_DIR ? ex * -0.11f : 0.0f);
UI_icon_draw_ex(icon_x,
icon_y,
icon,
icon_large,
icon_aspect / 4.0f / UI_SCALE_FAC,
document_img_col[3],
0.0f,

@ -1244,6 +1244,8 @@ static void graph_draw_driver_settings_panel(uiLayout *layout,
uiItemL(row, valBuf, ICON_NONE);
}
}
/* Quiet warning about old value being unused before re-assigned. */
UNUSED_VARS(block);
uiItemS(layout);
uiItemS(layout);

@ -1988,7 +1988,7 @@ static int sequencer_meta_make_exec(bContext *C, wmOperator *op)
for (int i = channel_min; i <= channel_max; i++) {
SeqTimelineChannel *channel_cur = SEQ_channel_get_by_index(channels_cur, i);
SeqTimelineChannel *channel_meta = SEQ_channel_get_by_index(channels_meta, i);
BLI_strncpy(channel_meta->name, channel_cur->name, sizeof(channel_meta->name));
STRNCPY(channel_meta->name, channel_cur->name);
channel_meta->flag = channel_cur->flag;
}

@ -24,7 +24,7 @@ void VKRenderGraphLink::debug_print(std::ostream &ss,
switch (tracked_resource.type) {
case VKResourceType::BUFFER: {
ss << "BUFFER";
ss << ", vk_handle=" << (uint64_t)tracked_resource.buffer.vk_buffer;
ss << ", vk_handle=" << uint64_t(tracked_resource.buffer.vk_buffer);
#ifndef NDEBUG
if (tracked_resource.name) {
ss << ", name=" << tracked_resource.name;
@ -35,7 +35,7 @@ void VKRenderGraphLink::debug_print(std::ostream &ss,
}
case VKResourceType::IMAGE: {
ss << "IMAGE";
ss << ", vk_handle=" << (uint64_t)tracked_resource.image.vk_image;
ss << ", vk_handle=" << uint64_t(tracked_resource.image.vk_image);
#ifndef NDEBUG
if (tracked_resource.name) {
ss << ", name=" << tracked_resource.name;

@ -53,7 +53,7 @@ PyC_StringEnumItems bpygpu_dataformat_items[] = {
/** \name Utilities
* \{ */
bool bpygpu_is_init_or_error(void)
bool bpygpu_is_init_or_error()
{
if (!GPU_is_init()) {
PyErr_SetString(PyExc_SystemError,

@ -634,7 +634,7 @@ static PyObject *app_translations_pgettext_n(BlenderAppTranslations * /*self*/,
PyObject *args,
PyObject *kw)
{
static const char *kwlist[] = {"msgid", "msgctxt", NULL};
static const char *kwlist[] = {"msgid", "msgctxt", nullptr};
PyObject *msgid, *msgctxt;
// (void)_pgettext;