diff options
| author | Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> | 2025-09-13 18:23:09 +0300 |
|---|---|---|
| committer | Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> | 2025-12-18 12:23:57 +0200 |
| commit | 0271a62e676d50940ec5f86d94cf66629894c25f (patch) | |
| tree | 6cafec033afba5469dbfacc1dd3e4c621bcdd0cc | |
| parent | bb4d48fbf9d0ad6be570d9c9b052f835f3a8b0d5 (diff) | |
fix: Replace C-style casts with C++ casts
This commit addresses cppcheck warnings about C-style casts (cstyleCast)
by replacing them with appropriate C++ casts. C-style casts are considered
dangerous because they can perform unsafe conversions without compile-time
type checking, while C++ casts are more explicit and type-safe.
Changes made:
- static_cast for safe type conversions (e.g., void* to struct*)
- reinterpret_cast for pointer type conversions (e.g., uint8_t* to char*)
- Combined static_cast and reinterpret_cast for integer-to-pointer conversions
Fixed files:
- kmscube/cube-gles2.cpp: GLvoid* casts for OpenGL vertex attribute pointers
- kmscube/cube-wl.cpp: Wayland interface pointer casts
- kmscube/cube-x11.cpp: X11 window handle conversion
- utils/fbtest.cpp: mmap return value cast
- utils/kmstest.cpp: Framebuffer pointer arithmetic
- utils/kmsview.cpp: Framebuffer memory mapping cast
| -rw-r--r-- | kmscube/cube-gles2.cpp | 6 | ||||
| -rw-r--r-- | kmscube/cube-wl.cpp | 6 | ||||
| -rw-r--r-- | kmscube/cube-x11.cpp | 2 | ||||
| -rw-r--r-- | utils/fbtest.cpp | 4 | ||||
| -rw-r--r-- | utils/kmstest.cpp | 2 | ||||
| -rw-r--r-- | utils/kmsview.cpp | 2 |
6 files changed, 11 insertions, 11 deletions
diff --git a/kmscube/cube-gles2.cpp b/kmscube/cube-gles2.cpp index 854c90e..0e52a32 100644 --- a/kmscube/cube-gles2.cpp +++ b/kmscube/cube-gles2.cpp @@ -200,11 +200,11 @@ GlScene::GlScene() glBufferSubData(GL_ARRAY_BUFFER, positionsoffset, sizeof(vVertices), &vVertices[0]); glBufferSubData(GL_ARRAY_BUFFER, colorsoffset, sizeof(vColors), &vColors[0]); glBufferSubData(GL_ARRAY_BUFFER, normalsoffset, sizeof(vNormals), &vNormals[0]); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)positionsoffset); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, reinterpret_cast<const GLvoid*>(positionsoffset)); glEnableVertexAttribArray(0); - glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)normalsoffset); + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, reinterpret_cast<const GLvoid*>(normalsoffset)); glEnableVertexAttribArray(1); - glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)colorsoffset); + glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, reinterpret_cast<const GLvoid*>(colorsoffset)); glEnableVertexAttribArray(2); } diff --git a/kmscube/cube-wl.cpp b/kmscube/cube-wl.cpp index 136a4ed..95ad5c3 100644 --- a/kmscube/cube-wl.cpp +++ b/kmscube/cube-wl.cpp @@ -23,9 +23,9 @@ struct window { static void registry_add_object(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version) { if (!strcmp(interface, "wl_compositor")) - s_compositor = (struct wl_compositor*)wl_registry_bind(registry, name, &wl_compositor_interface, 0); + s_compositor = static_cast<struct wl_compositor*>(wl_registry_bind(registry, name, &wl_compositor_interface, 0)); else if (!strcmp(interface, "wl_shell")) - s_shell = (struct wl_shell*)wl_registry_bind(registry, name, &wl_shell_interface, 0); + s_shell = static_cast<struct wl_shell*>(wl_registry_bind(registry, name, &wl_shell_interface, 0)); } static void registry_remove_object(void* data, struct wl_registry* registry, uint32_t name) @@ -41,7 +41,7 @@ static void shell_surface_ping(void* data, struct wl_shell_surface* shell_surfac static void shell_surface_configure(void* data, struct wl_shell_surface* shell_surface, uint32_t edges, int32_t width, int32_t height) { - struct window* window = (struct window*)data; + struct window* window = static_cast<struct window*>(data); wl_egl_window_resize(window->egl_window, width, height, 0, 0); } diff --git a/kmscube/cube-x11.cpp b/kmscube/cube-x11.cpp index ae018ea..eb57616 100644 --- a/kmscube/cube-x11.cpp +++ b/kmscube/cube-x11.cpp @@ -13,7 +13,7 @@ using namespace std; static void main_loop(Display* dpy, xcb_connection_t* c, xcb_window_t window, uint32_t width, uint32_t height) { EglState egl(dpy); - EglSurface surface(egl, (void*)(uintptr_t)window); + EglSurface surface(egl, reinterpret_cast<void*>(static_cast<uintptr_t>(window))); GlScene scene; scene.set_viewport(width, height); diff --git a/utils/fbtest.cpp b/utils/fbtest.cpp index 913d773..4992895 100644 --- a/utils/fbtest.cpp +++ b/utils/fbtest.cpp @@ -33,10 +33,10 @@ int main(int argc, char** argv) r = ioctl(fd, FBIOGET_FSCREENINFO, &fix); FAIL_IF(r, "FBIOGET_FSCREENINFO failed"); - uint8_t* ptr = (uint8_t*)mmap(NULL, + uint8_t* ptr = static_cast<uint8_t*>(mmap(NULL, var.yres_virtual * fix.line_length, PROT_WRITE | PROT_READ, - MAP_SHARED, fd, 0); + MAP_SHARED, fd, 0)); FAIL_IF(ptr == MAP_FAILED, "mmap failed"); diff --git a/utils/kmstest.cpp b/utils/kmstest.cpp index 8340fa7..c6efb45 100644 --- a/utils/kmstest.cpp +++ b/utils/kmstest.cpp @@ -748,7 +748,7 @@ static string fb_crc(IFramebuffer* fb) for (unsigned y = 0; y < fb->height(); ++y) { for (unsigned x = 0; x < fb->width(); ++x) { - uint32_t* p32 = (uint32_t*)(p + fb->stride(0) * y + x * 4); + uint32_t* p32 = reinterpret_cast<uint32_t*>(p + fb->stride(0) * y + x * 4); RGB rgb(*p32); r = crc16(r, rgb.r); diff --git a/utils/kmsview.cpp b/utils/kmsview.cpp index 437d3a6..4b60bb8 100644 --- a/utils/kmsview.cpp +++ b/utils/kmsview.cpp @@ -12,7 +12,7 @@ using namespace kms; static void read_frame(ifstream& is, DumbFramebuffer* fb, Crtc* crtc, Plane* plane) { for (unsigned i = 0; i < fb->num_planes(); ++i) - is.read((char*)fb->map(i), fb->size(i)); + is.read(reinterpret_cast<char*>(fb->map(i)), fb->size(i)); unsigned w = min(crtc->width(), fb->width()); unsigned h = min(crtc->height(), fb->height()); |
