From cf374242034f78dd66343c87f482409e9ae63427 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 17 Apr 2024 11:36:38 +1000 Subject: [PATCH] Cleanup: use const pointers, quiet cppcheck unreadVariable warning --- intern/ghost/intern/GHOST_SystemWayland.cc | 4 ++-- intern/ghost/intern/GHOST_WindowWayland.cc | 2 +- intern/guardedalloc/intern/mallocn_guarded_impl.cc | 6 +++--- source/blender/blenkernel/intern/pointcache.cc | 3 ++- source/blender/blenlib/BLI_array_store.h | 2 +- source/blender/blenlib/intern/array_store.cc | 2 +- source/blender/blenlib/intern/math_rotation.c | 6 +++--- source/blender/blenlib/intern/string.c | 1 + source/blender/blenloader/intern/readfile.cc | 2 +- source/blender/editors/interface/interface_widgets.cc | 2 +- source/blender/editors/interface/resources.cc | 2 +- source/blender/editors/util/ed_util_imbuf.cc | 2 +- source/blender/geometry/intern/uv_parametrizer.cc | 4 ++-- source/blender/imbuf/intern/cineon/cineon_dpx.cc | 2 +- source/blender/makesdna/intern/dna_utils.cc | 1 + source/blender/python/intern/bpy_utils_units.cc | 3 ++- 16 files changed, 24 insertions(+), 20 deletions(-) diff --git a/intern/ghost/intern/GHOST_SystemWayland.cc b/intern/ghost/intern/GHOST_SystemWayland.cc index 36ead30206c..89b4a056a70 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.cc +++ b/intern/ghost/intern/GHOST_SystemWayland.cc @@ -7900,7 +7900,7 @@ GHOST_TSuccess GHOST_SystemWayland::getCursorPositionClientRelative(const GHOST_ if (UNLIKELY(!seat)) { return GHOST_kFailure; } - GWL_SeatStatePointer *seat_state_pointer = gwl_seat_state_pointer_active(seat); + const GWL_SeatStatePointer *seat_state_pointer = gwl_seat_state_pointer_active(seat); if (!seat_state_pointer || !seat_state_pointer->wl.surface_window) { return GHOST_kFailure; } @@ -7934,7 +7934,7 @@ GHOST_TSuccess GHOST_SystemWayland::getCursorPosition(int32_t &x, int32_t &y) co if (UNLIKELY(!seat)) { return GHOST_kFailure; } - GWL_SeatStatePointer *seat_state_pointer = gwl_seat_state_pointer_active(seat); + const GWL_SeatStatePointer *seat_state_pointer = gwl_seat_state_pointer_active(seat); if (!seat_state_pointer) { return GHOST_kFailure; } diff --git a/intern/ghost/intern/GHOST_WindowWayland.cc b/intern/ghost/intern/GHOST_WindowWayland.cc index 78ad90cd81a..75ff9cdf849 100644 --- a/intern/ghost/intern/GHOST_WindowWayland.cc +++ b/intern/ghost/intern/GHOST_WindowWayland.cc @@ -2056,7 +2056,7 @@ GHOST_TSuccess GHOST_WindowWayland::setWindowCursorGrab(GHOST_TGrabCursorMode mo #endif GHOST_Rect bounds_buf; - GHOST_Rect *bounds = nullptr; + const GHOST_Rect *bounds = nullptr; if (m_cursorGrab == GHOST_kGrabWrap) { if (getCursorGrabBounds(bounds_buf) == GHOST_kFailure) { getClientBounds(bounds_buf); diff --git a/intern/guardedalloc/intern/mallocn_guarded_impl.cc b/intern/guardedalloc/intern/mallocn_guarded_impl.cc index 0256675b840..50185d54423 100644 --- a/intern/guardedalloc/intern/mallocn_guarded_impl.cc +++ b/intern/guardedalloc/intern/mallocn_guarded_impl.cc @@ -150,7 +150,7 @@ static void addtail(volatile localListBase *listbase, void *vlink); static void remlink(volatile localListBase *listbase, void *vlink); static void rem_memblock(MemHead *memh); static void MemorY_ErroR(const char *block, const char *error); -static const char *check_memlist(MemHead *memh); +static const char *check_memlist(const MemHead *memh); /* --------------------------------------------------------------------- */ /* locally used defines */ @@ -235,7 +235,7 @@ static void mem_unlock_thread() bool MEM_guarded_consistency_check() { const char *err_val = nullptr; - MemHead *listend; + const MemHead *listend; /* check_memlist starts from the front, and runs until it finds * the requested chunk. For this test, that's the last one. */ listend = static_cast(membase->last); @@ -1100,7 +1100,7 @@ static void MemorY_ErroR(const char *block, const char *error) #endif } -static const char *check_memlist(MemHead *memh) +static const char *check_memlist(const MemHead *memh) { MemHead *forw, *back, *forwok, *backok; const char *name; diff --git a/source/blender/blenkernel/intern/pointcache.cc b/source/blender/blenkernel/intern/pointcache.cc index fc9bf0f0804..878b25c6364 100644 --- a/source/blender/blenkernel/intern/pointcache.cc +++ b/source/blender/blenkernel/intern/pointcache.cc @@ -1412,7 +1412,7 @@ static int ptcache_filepath(PTCacheID *pid, const bool do_ext) { int len = 0; - char *idname; + const char *idname; char *newname; filepath[0] = '\0'; newname = filepath; @@ -1444,6 +1444,7 @@ static int ptcache_filepath(PTCacheID *pid, newname += temp; len += temp; } + UNUSED_VARS(newname); if (do_ext) { len += ptcache_filepath_ext_append(pid, filepath, size_t(len), true, cfra); diff --git a/source/blender/blenlib/BLI_array_store.h b/source/blender/blenlib/BLI_array_store.h index 81634700453..3ccdc182f1f 100644 --- a/source/blender/blenlib/BLI_array_store.h +++ b/source/blender/blenlib/BLI_array_store.h @@ -88,7 +88,7 @@ size_t BLI_array_store_state_size_get(BArrayState *state); /** * Fill in existing allocated memory with the contents of \a state. */ -void BLI_array_store_state_data_get(BArrayState *state, void *data); +void BLI_array_store_state_data_get(const BArrayState *state, void *data); /** * Allocate an array for \a state and return it. */ diff --git a/source/blender/blenlib/intern/array_store.cc b/source/blender/blenlib/intern/array_store.cc index a0a863c10eb..0449142b21a 100644 --- a/source/blender/blenlib/intern/array_store.cc +++ b/source/blender/blenlib/intern/array_store.cc @@ -1687,7 +1687,7 @@ size_t BLI_array_store_state_size_get(BArrayState *state) return state->chunk_list->total_expanded_size; } -void BLI_array_store_state_data_get(BArrayState *state, void *data) +void BLI_array_store_state_data_get(const BArrayState *state, void *data) { #ifdef USE_PARANOID_CHECKS size_t data_test_len = 0; diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c index d3d47dd847a..0344373c3fc 100644 --- a/source/blender/blenlib/intern/math_rotation.c +++ b/source/blender/blenlib/intern/math_rotation.c @@ -1971,7 +1971,7 @@ void sub_eul_euleul(float r_eul[3], float a[3], float b[3], const short order) void mat4_to_dquat(DualQuat *dq, const float basemat[4][4], const float mat[4][4]) { - float *t, *q, dscale[3], scale[3], basequat[4], mat3[3][3]; + float dscale[3], scale[3], basequat[4], mat3[3][3]; float baseRS[4][4], baseinv[4][4], baseR[4][4], baseRinv[4][4]; float R[4][4], S[4][4]; @@ -2020,8 +2020,8 @@ void mat4_to_dquat(DualQuat *dq, const float basemat[4][4], const float mat[4][4 mat4_to_quat(dq->quat, R); /* dual part */ - t = R[3]; - q = dq->quat; + const float *t = R[3]; + const float *q = dq->quat; dq->trans[0] = -0.5f * (t[0] * q[1] + t[1] * q[2] + t[2] * q[3]); dq->trans[1] = 0.5f * (t[0] * q[0] + t[1] * q[3] - t[2] * q[2]); dq->trans[2] = 0.5f * (-t[0] * q[3] + t[1] * q[0] + t[2] * q[1]); diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index ea513f63250..c4a44cbec63 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -260,6 +260,7 @@ char *BLI_sprintfN_with_buffer( retval = vsnprintf(result, size, format, args); va_end(args); BLI_assert((size_t)(retval + 1) == size); + UNUSED_VARS_NDEBUG(retval); return result; } diff --git a/source/blender/blenloader/intern/readfile.cc b/source/blender/blenloader/intern/readfile.cc index c374a77fd04..688fea8210d 100644 --- a/source/blender/blenloader/intern/readfile.cc +++ b/source/blender/blenloader/intern/readfile.cc @@ -1385,7 +1385,7 @@ BlendThumbnail *BLO_thumbnail_from_file(const char *filepath) { FileData *fd; BlendThumbnail *data = nullptr; - int *fd_data; + const int *fd_data; fd = blo_filedata_from_file_minimal(filepath); fd_data = fd ? read_file_thumbnail(fd) : nullptr; diff --git a/source/blender/editors/interface/interface_widgets.cc b/source/blender/editors/interface/interface_widgets.cc index c337ae38aa1..b9cbaaf502a 100644 --- a/source/blender/editors/interface/interface_widgets.cc +++ b/source/blender/editors/interface/interface_widgets.cc @@ -5338,7 +5338,7 @@ void ui_draw_pie_center(uiBlock *block) const float cx = block->pie_data.pie_center_spawned[0]; const float cy = block->pie_data.pie_center_spawned[1]; - float *pie_dir = block->pie_data.pie_dir; + const float *pie_dir = block->pie_data.pie_dir; const float pie_radius_internal = UI_SCALE_FAC * U.pie_menu_threshold; const float pie_radius_external = UI_SCALE_FAC * (U.pie_menu_threshold + 7.0f); diff --git a/source/blender/editors/interface/resources.cc b/source/blender/editors/interface/resources.cc index e4f724eea0e..beb2e09ae16 100644 --- a/source/blender/editors/interface/resources.cc +++ b/source/blender/editors/interface/resources.cc @@ -1514,7 +1514,7 @@ void UI_ThemeClearColor(int colorid) int UI_ThemeMenuShadowWidth() { - bTheme *btheme = UI_GetTheme(); + const bTheme *btheme = UI_GetTheme(); return int(btheme->tui.menu_shadow_width * UI_SCALE_FAC); } diff --git a/source/blender/editors/util/ed_util_imbuf.cc b/source/blender/editors/util/ed_util_imbuf.cc index 294b4492d23..dbcd8b04b32 100644 --- a/source/blender/editors/util/ed_util_imbuf.cc +++ b/source/blender/editors/util/ed_util_imbuf.cc @@ -298,7 +298,7 @@ static void sequencer_sample_apply(bContext *C, wmOperator *op, const wmEvent *e if (fx >= 0.0f && fy >= 0.0f && fx < ibuf->x && fy < ibuf->y) { const float *fp; - uchar *cp; + const uchar *cp; int x = int(fx), y = int(fy); info->x = x; diff --git a/source/blender/geometry/intern/uv_parametrizer.cc b/source/blender/geometry/intern/uv_parametrizer.cc index f106d24bbe0..e97bc832c0a 100644 --- a/source/blender/geometry/intern/uv_parametrizer.cc +++ b/source/blender/geometry/intern/uv_parametrizer.cc @@ -735,7 +735,7 @@ static int p_face_exists(ParamHandle *handle, const ParamKey *pvkeys, int i1, in static bool p_edge_implicit_seam(PEdge *e, PEdge *ep) { - float *uv1, *uv2, *uvp1, *uvp2; + const float *uv1, *uv2, *uvp1, *uvp2; float limit[2]; limit[0] = 0.00001; @@ -771,7 +771,7 @@ static bool p_edge_has_pair(ParamHandle *handle, PEdge *e, bool topology_from_uv { PHashKey key; PEdge *pe; - PVert *v1, *v2; + const PVert *v1, *v2; PHashKey key1 = e->vert->u.key; PHashKey key2 = e->next->vert->u.key; diff --git a/source/blender/imbuf/intern/cineon/cineon_dpx.cc b/source/blender/imbuf/intern/cineon/cineon_dpx.cc index 05c150ac89f..fdd9d4f3790 100644 --- a/source/blender/imbuf/intern/cineon/cineon_dpx.cc +++ b/source/blender/imbuf/intern/cineon/cineon_dpx.cc @@ -70,7 +70,7 @@ static int imb_save_dpx_cineon(ImBuf *ibuf, const char *filepath, int use_cineon LogImageFile *logImage; float *fbuf; float *fbuf_ptr; - uchar *rect_ptr; + const uchar *rect_ptr; int x, y, depth, bitspersample, rvalue; if (flags & IB_mem) { diff --git a/source/blender/makesdna/intern/dna_utils.cc b/source/blender/makesdna/intern/dna_utils.cc index 592f8a8c44d..50e97770334 100644 --- a/source/blender/makesdna/intern/dna_utils.cc +++ b/source/blender/makesdna/intern/dna_utils.cc @@ -158,6 +158,7 @@ char *DNA_elem_id_rename(MemArena *mem_arena, i += elem_full_tail_len; } BLI_assert((strlen(elem_dst_full) == elem_final_len) && (i == elem_final_len)); + UNUSED_VARS_NDEBUG(i); return elem_dst_full; } diff --git a/source/blender/python/intern/bpy_utils_units.cc b/source/blender/python/intern/bpy_utils_units.cc index 87dfbedff7b..3dc152daa80 100644 --- a/source/blender/python/intern/bpy_utils_units.cc +++ b/source/blender/python/intern/bpy_utils_units.cc @@ -310,7 +310,8 @@ static PyObject *bpyunits_to_string(PyObject * /*self*/, PyObject *args, PyObjec * (spaces, trailing '\0'...). * So in practice, 64 should be more than enough. */ - char buf1[64], buf2[64], *str; + char buf1[64], buf2[64]; + const char *str; PyObject *result; BKE_unit_value_as_string_adaptive(