From 784e13170e67651cce9c75cacd7f9dc84aceff52 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 4 Jun 2023 19:07:26 +1000 Subject: [PATCH] Cleanup: function style casts, use nullptr, printf & size macros --- .../intern/grease_pencil_convert_legacy.cc | 8 ++++---- source/blender/blenkernel/intern/light_linking.cc | 2 +- source/blender/blenloader/intern/versioning_280.cc | 4 ++-- source/blender/blenloader/intern/versioning_300.cc | 2 +- .../blender/draw/engines/select/select_instance.cc | 14 +++++++------- source/blender/draw/intern/draw_cache.c | 8 ++++---- .../editors/space_view3d/view3d_navigate.cc | 4 ++-- source/blender/editors/transform/transform_snap.cc | 2 +- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/source/blender/blenkernel/intern/grease_pencil_convert_legacy.cc b/source/blender/blenkernel/intern/grease_pencil_convert_legacy.cc index 27000cc4c31..d54f89b77d8 100644 --- a/source/blender/blenkernel/intern/grease_pencil_convert_legacy.cc +++ b/source/blender/blenkernel/intern/grease_pencil_convert_legacy.cc @@ -98,9 +98,9 @@ void legacy_gpencil_frame_to_grease_pencil_drawing(const bGPDframe &gpf, /* Write curve attributes. */ stroke_cyclic.span[stroke_i] = (gps->flag & GP_STROKE_CYCLIC) != 0; /* TODO: This should be a `double` attribute. */ - stroke_init_times.span[stroke_i] = static_cast(gps->inittime); - stroke_start_caps.span[stroke_i] = static_cast(gps->caps[0]); - stroke_end_caps.span[stroke_i] = static_cast(gps->caps[1]); + stroke_init_times.span[stroke_i] = float(gps->inittime); + stroke_start_caps.span[stroke_i] = int8_t(gps->caps[0]); + stroke_end_caps.span[stroke_i] = int8_t(gps->caps[1]); stroke_hardnesses.span[stroke_i] = gps->hardeness; stroke_point_aspect_ratios.span[stroke_i] = gps->aspect_ratio[0] / max_ff(gps->aspect_ratio[1], 1e-8); @@ -207,7 +207,7 @@ void legacy_gpencil_to_grease_pencil(Main &bmain, GreasePencil &grease_pencil, b (gpl->onion_flag & GP_LAYER_ONIONSKIN), GP_LAYER_TREE_NODE_USE_ONION_SKINNING); - new_layer.blend_mode = static_cast(gpl->blend_mode); + new_layer.blend_mode = int8_t(gpl->blend_mode); /* Convert the layer masks. */ LISTBASE_FOREACH (bGPDlayer_Mask *, mask, &gpl->mask_layers) { diff --git a/source/blender/blenkernel/intern/light_linking.cc b/source/blender/blenkernel/intern/light_linking.cc index 4603f9d7de7..03290370bd9 100644 --- a/source/blender/blenkernel/intern/light_linking.cc +++ b/source/blender/blenkernel/intern/light_linking.cc @@ -67,7 +67,7 @@ static std::string get_default_collection_name(const Object *object, } char name[MAX_ID_NAME]; - BLI_snprintf(name, sizeof(name), format, object->id.name + 2); + SNPRINTF(name, format, object->id.name + 2); return name; } diff --git a/source/blender/blenloader/intern/versioning_280.cc b/source/blender/blenloader/intern/versioning_280.cc index 285d117c7fa..51f4482d51e 100644 --- a/source/blender/blenloader/intern/versioning_280.cc +++ b/source/blender/blenloader/intern/versioning_280.cc @@ -4098,8 +4098,8 @@ void blo_do_versions_280(FileData *fd, Library * /*lib*/, Main *bmain) UnitSettings *unit = &scene->unit; if (unit->system == USER_UNIT_NONE) { - unit->length_unit = (char)USER_UNIT_ADAPTIVE; - unit->mass_unit = (char)USER_UNIT_ADAPTIVE; + unit->length_unit = char(USER_UNIT_ADAPTIVE); + unit->mass_unit = char(USER_UNIT_ADAPTIVE); } RenderData *render_data = &scene->r; diff --git a/source/blender/blenloader/intern/versioning_300.cc b/source/blender/blenloader/intern/versioning_300.cc index 7aacc494e3d..4a27a6ddd75 100644 --- a/source/blender/blenloader/intern/versioning_300.cc +++ b/source/blender/blenloader/intern/versioning_300.cc @@ -4480,7 +4480,7 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) } FOREACH_NODETREE_END; - BKE_animdata_main_cb(bmain, version_liboverride_nla_frame_start_end, NULL); + BKE_animdata_main_cb(bmain, version_liboverride_nla_frame_start_end, nullptr); /* Store simulation bake directory in geometry nodes modifier. */ LISTBASE_FOREACH (Object *, ob, &bmain->objects) { diff --git a/source/blender/draw/engines/select/select_instance.cc b/source/blender/draw/engines/select/select_instance.cc index 94a74560e2e..e9e31d5ffe2 100644 --- a/source/blender/draw/engines/select/select_instance.cc +++ b/source/blender/draw/engines/select/select_instance.cc @@ -99,21 +99,21 @@ static void SELECT_next_instance_free(void *instance_) static const DrawEngineDataSize SELECT_next_data_size = DRW_VIEWPORT_DATA_SIZE(SELECT_NextData); DrawEngineType draw_engine_select_next_type = { - NULL, - NULL, + nullptr, + nullptr, N_("Select-Next"), &SELECT_next_data_size, &SELECT_next_engine_init, - NULL, + nullptr, &SELECT_next_instance_free, &SELECT_next_cache_init, &SELECT_next_cache_populate, &SELECT_next_cache_finish, &SELECT_next_draw_scene, - NULL, - NULL, - NULL, - NULL, + nullptr, + nullptr, + nullptr, + nullptr, }; /** \} */ diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c index 98707cc98e4..5080e8ce53b 100644 --- a/source/blender/draw/intern/draw_cache.c +++ b/source/blender/draw/intern/draw_cache.c @@ -2466,7 +2466,7 @@ static float x_axis_name[4][2] = { {-0.9f * S_X, 1.0f * S_Y}, {1.0f * S_X, -1.0f * S_Y}, }; -#define X_LEN (sizeof(x_axis_name) / sizeof(float[2])) +#define X_LEN (ARRAY_SIZE(x_axis_name)) #undef S_X #undef S_Y @@ -2480,7 +2480,7 @@ static float y_axis_name[6][2] = { {0.0f * S_X, -0.1f * S_Y}, {0.0f * S_X, -1.0f * S_Y}, }; -#define Y_LEN (sizeof(y_axis_name) / sizeof(float[2])) +#define Y_LEN (ARRAY_SIZE(y_axis_name)) #undef S_X #undef S_Y @@ -2498,7 +2498,7 @@ static float z_axis_name[10][2] = { {-1.00f * S_X, -1.00f * S_Y}, {1.00f * S_X, -1.00f * S_Y}, }; -#define Z_LEN (sizeof(z_axis_name) / sizeof(float[2])) +#define Z_LEN (ARRAY_SIZE(z_axis_name)) #undef S_X #undef S_Y @@ -2525,7 +2525,7 @@ static float axis_marker[8][2] = { {-S_X, 0.0f} #endif }; -#define MARKER_LEN (sizeof(axis_marker) / sizeof(float[2])) +#define MARKER_LEN (ARRAY_SIZE(axis_marker)) #define MARKER_FILL_LAYER 6 #undef S_X #undef S_Y diff --git a/source/blender/editors/space_view3d/view3d_navigate.cc b/source/blender/editors/space_view3d/view3d_navigate.cc index 11c0d1c7162..61e1d1f460f 100644 --- a/source/blender/editors/space_view3d/view3d_navigate.cc +++ b/source/blender/editors/space_view3d/view3d_navigate.cc @@ -1969,7 +1969,7 @@ static eV3D_OpMode view3d_navigation_type_from_idname(const char *idname) ViewOpsData *ED_view3d_navigation_init(bContext *C) { if (!CTX_wm_region_view3d(C)) { - return NULL; + return nullptr; } ViewOpsData *vod = MEM_cnew(__func__); @@ -2069,7 +2069,7 @@ bool ED_view3d_navigation_do(bContext *C, ViewOpsData *vod, const wmEvent *event /* Although #ED_view3d_update_viewmat is already called when redrawing the 3D View, do it here * as well, so the updated matrix values can be accessed by the operator. */ ED_view3d_update_viewmat( - vod->depsgraph, vod->scene, vod->v3d, vod->region, NULL, NULL, NULL, false); + vod->depsgraph, vod->scene, vod->v3d, vod->region, nullptr, nullptr, nullptr, false); return true; } diff --git a/source/blender/editors/transform/transform_snap.cc b/source/blender/editors/transform/transform_snap.cc index 1037f7f8936..d6727182f55 100644 --- a/source/blender/editors/transform/transform_snap.cc +++ b/source/blender/editors/transform/transform_snap.cc @@ -1160,7 +1160,7 @@ static void snap_multipoints_free(TransInfo *t) if (t->tsnap.status & SNAP_MULTI_POINTS) { BLI_freelistN(&t->tsnap.points); t->tsnap.status &= ~SNAP_MULTI_POINTS; - t->tsnap.selectedPoint = NULL; + t->tsnap.selectedPoint = nullptr; } }