summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomi Valkeinen <tomi.valkeinen@ideasonboard.com>2025-09-13 17:40:42 +0300
committerTomi Valkeinen <tomi.valkeinen@ideasonboard.com>2025-12-18 12:23:57 +0200
commit7cc1bdd06e68ab81612e8feee2a1dedf0e392886 (patch)
tree99415217574312a3ac7b22a8fcb84aa27ab156fa
parent2efdd2583da9575242091bb53c57a311c3eacbc6 (diff)
fix: Replace C-style casts with C++ static/reinterpret casts
C-style casts should be replaced with appropriate C++ cast operators for better type safety and code clarity. This change fixes cppcheck style warnings about C-style pointer casting by using: - static_cast for simple pointer type conversions - reinterpret_cast for memory buffer pointer arithmetic The changes maintain identical functionality while following modern C++ best practices for explicit casting.
-rw-r--r--kms++/src/blob.cpp2
-rw-r--r--kms++/src/card.cpp2
-rw-r--r--kms++/src/dmabufframebuffer.cpp4
-rw-r--r--kms++/src/dumbframebuffer.cpp4
-rw-r--r--kms++/src/omap/omapframebuffer.cpp2
-rw-r--r--kms++util/src/colorbar.cpp6
-rw-r--r--kms++util/src/drawing.cpp60
7 files changed, 40 insertions, 40 deletions
diff --git a/kms++/src/blob.cpp b/kms++/src/blob.cpp
index 431863a..69914f6 100644
--- a/kms++/src/blob.cpp
+++ b/kms++/src/blob.cpp
@@ -38,7 +38,7 @@ vector<uint8_t> Blob::data()
if (!blob)
throw invalid_argument("Blob data not available");
- uint8_t* data = (uint8_t*)blob->data;
+ uint8_t* data = static_cast<uint8_t*>(blob->data);
auto v = vector<uint8_t>(data, data + blob->length);
diff --git a/kms++/src/card.cpp b/kms++/src/card.cpp
index 935969d..d0af8a4 100644
--- a/kms++/src/card.cpp
+++ b/kms++/src/card.cpp
@@ -393,7 +393,7 @@ static void page_flip_handler(int fd, unsigned int frame,
unsigned int sec, unsigned int usec,
void* data)
{
- auto handler = (PageFlipHandlerBase*)data;
+ auto handler = static_cast<PageFlipHandlerBase*>(data);
double time = sec + usec / 1000000.0;
handler->handle_page_flip(frame, time);
}
diff --git a/kms++/src/dmabufframebuffer.cpp b/kms++/src/dmabufframebuffer.cpp
index 939c025..33d65f7 100644
--- a/kms++/src/dmabufframebuffer.cpp
+++ b/kms++/src/dmabufframebuffer.cpp
@@ -97,8 +97,8 @@ uint8_t* DmabufFramebuffer::map(unsigned plane)
if (p.map)
return p.map;
- p.map = (uint8_t*)mmap(0, p.size, PROT_READ | PROT_WRITE, MAP_SHARED,
- p.prime_fd, 0);
+ p.map = static_cast<uint8_t*>(mmap(0, p.size, PROT_READ | PROT_WRITE, MAP_SHARED,
+ p.prime_fd, 0));
if (p.map == MAP_FAILED)
throw invalid_argument(string("mmap failed: ") + strerror(errno));
diff --git a/kms++/src/dumbframebuffer.cpp b/kms++/src/dumbframebuffer.cpp
index e035061..6b623b3 100644
--- a/kms++/src/dumbframebuffer.cpp
+++ b/kms++/src/dumbframebuffer.cpp
@@ -119,8 +119,8 @@ uint8_t* DumbFramebuffer::map(unsigned plane)
throw invalid_argument(string("DRM_IOCTL_MODE_MAP_DUMB failed: ") + strerror(errno));
/* perform actual memory mapping */
- p.map = (uint8_t*)mmap(0, p.size, PROT_READ | PROT_WRITE, MAP_SHARED,
- card().fd(), mreq.offset);
+ p.map = static_cast<uint8_t*>(mmap(0, p.size, PROT_READ | PROT_WRITE, MAP_SHARED,
+ card().fd(), mreq.offset));
if (p.map == MAP_FAILED)
throw invalid_argument(string("mmap failed: ") + strerror(errno));
diff --git a/kms++/src/omap/omapframebuffer.cpp b/kms++/src/omap/omapframebuffer.cpp
index 9f9d7c7..4a94202 100644
--- a/kms++/src/omap/omapframebuffer.cpp
+++ b/kms++/src/omap/omapframebuffer.cpp
@@ -167,7 +167,7 @@ uint8_t* OmapFramebuffer::map(unsigned plane)
if (p.map)
return p.map;
- p.map = (uint8_t*)omap_bo_map(p.omap_bo);
+ p.map = static_cast<uint8_t*>(omap_bo_map(p.omap_bo));
if (p.map == MAP_FAILED)
throw invalid_argument(string("mmap failed: ") + strerror(errno));
diff --git a/kms++util/src/colorbar.cpp b/kms++util/src/colorbar.cpp
index c727306..ec59806 100644
--- a/kms++util/src/colorbar.cpp
+++ b/kms++util/src/colorbar.cpp
@@ -39,7 +39,7 @@ static void drm_draw_color_bar_rgb888(IFramebuffer& buf, int old_xpos, int xpos,
{
for (unsigned y = 0; y < buf.height(); ++y) {
RGB bcol = colors32[y * ARRAY_SIZE(colors32) / buf.height()];
- uint32_t* line = (uint32_t*)(buf.map(0) + buf.stride(0) * y);
+ uint32_t* line = reinterpret_cast<uint32_t*>(buf.map(0) + buf.stride(0) * y);
if (old_xpos >= 0) {
for (int x = old_xpos; x < old_xpos + width; ++x)
@@ -57,7 +57,7 @@ static void drm_draw_color_bar_rgb565(IFramebuffer& buf, int old_xpos, int xpos,
for (unsigned y = 0; y < buf.height(); ++y) {
uint16_t bcol = colors16[y * ARRAY_SIZE(colors16) / buf.height()];
- uint16_t* line = (uint16_t*)(buf.map(0) + buf.stride(0) * y);
+ uint16_t* line = reinterpret_cast<uint16_t*>(buf.map(0) + buf.stride(0) * y);
if (old_xpos >= 0) {
for (int x = old_xpos; x < old_xpos + width; ++x)
@@ -85,7 +85,7 @@ static void drm_draw_color_bar_semiplanar_yuv(IFramebuffer& buf, int old_xpos, i
for (unsigned y = 0; y < buf.height(); ++y) {
unsigned int bcol = colors[y * ARRAY_SIZE(colors) / buf.height()];
- uint8_t* line = (uint8_t*)(buf.map(0) + buf.stride(0) * y);
+ uint8_t* line = reinterpret_cast<uint8_t*>(buf.map(0) + buf.stride(0) * y);
if (old_xpos >= 0) {
for (int x = old_xpos; x < old_xpos + width; ++x)
diff --git a/kms++util/src/drawing.cpp b/kms++util/src/drawing.cpp
index 7e3ca97..df02485 100644
--- a/kms++util/src/drawing.cpp
+++ b/kms++util/src/drawing.cpp
@@ -17,49 +17,49 @@ void draw_rgb_pixel(IFramebuffer& buf, unsigned x, unsigned y, RGB color)
switch (buf.format()) {
case PixelFormat::XRGB8888:
case PixelFormat::ARGB8888: {
- uint32_t* p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
+ uint32_t* p = reinterpret_cast<uint32_t*>(buf.map(0) + buf.stride(0) * y + x * 4);
*p = color.argb8888();
break;
}
case PixelFormat::XBGR8888:
case PixelFormat::ABGR8888: {
- uint32_t* p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
+ uint32_t* p = reinterpret_cast<uint32_t*>(buf.map(0) + buf.stride(0) * y + x * 4);
*p = color.abgr8888();
break;
}
case PixelFormat::RGBX8888:
case PixelFormat::RGBA8888: {
- uint32_t* p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
+ uint32_t* p = reinterpret_cast<uint32_t*>(buf.map(0) + buf.stride(0) * y + x * 4);
*p = color.rgba8888();
break;
}
case PixelFormat::BGRX8888:
case PixelFormat::BGRA8888: {
- uint32_t* p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
+ uint32_t* p = reinterpret_cast<uint32_t*>(buf.map(0) + buf.stride(0) * y + x * 4);
*p = color.bgra8888();
break;
}
case PixelFormat::XRGB2101010:
case PixelFormat::ARGB2101010: {
- uint32_t* p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
+ uint32_t* p = reinterpret_cast<uint32_t*>(buf.map(0) + buf.stride(0) * y + x * 4);
*p = color.argb2101010();
break;
}
case PixelFormat::XBGR2101010:
case PixelFormat::ABGR2101010: {
- uint32_t* p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
+ uint32_t* p = reinterpret_cast<uint32_t*>(buf.map(0) + buf.stride(0) * y + x * 4);
*p = color.abgr2101010();
break;
}
case PixelFormat::RGBX1010102:
case PixelFormat::RGBA1010102: {
- uint32_t* p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
+ uint32_t* p = reinterpret_cast<uint32_t*>(buf.map(0) + buf.stride(0) * y + x * 4);
*p = color.rgba1010102();
break;
}
case PixelFormat::BGRX1010102:
case PixelFormat::BGRA1010102: {
- uint32_t* p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
+ uint32_t* p = reinterpret_cast<uint32_t*>(buf.map(0) + buf.stride(0) * y + x * 4);
*p = color.bgra1010102();
break;
}
@@ -78,29 +78,29 @@ void draw_rgb_pixel(IFramebuffer& buf, unsigned x, unsigned y, RGB color)
break;
}
case PixelFormat::RGB332: {
- uint8_t* p = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x);
+ uint8_t* p = reinterpret_cast<uint8_t*>(buf.map(0) + buf.stride(0) * y + x);
*p = color.rgb332();
break;
}
case PixelFormat::RGB565: {
- uint16_t* p = (uint16_t*)(buf.map(0) + buf.stride(0) * y + x * 2);
+ uint16_t* p = reinterpret_cast<uint16_t*>(buf.map(0) + buf.stride(0) * y + x * 2);
*p = color.rgb565();
break;
}
case PixelFormat::BGR565: {
- uint16_t* p = (uint16_t*)(buf.map(0) + buf.stride(0) * y + x * 2);
+ uint16_t* p = reinterpret_cast<uint16_t*>(buf.map(0) + buf.stride(0) * y + x * 2);
*p = color.bgr565();
break;
}
case PixelFormat::XRGB4444:
case PixelFormat::ARGB4444: {
- uint16_t* p = (uint16_t*)(buf.map(0) + buf.stride(0) * y + x * 2);
+ uint16_t* p = reinterpret_cast<uint16_t*>(buf.map(0) + buf.stride(0) * y + x * 2);
*p = color.argb4444();
break;
}
case PixelFormat::XRGB1555:
case PixelFormat::ARGB1555: {
- uint16_t* p = (uint16_t*)(buf.map(0) + buf.stride(0) * y + x * 2);
+ uint16_t* p = reinterpret_cast<uint16_t*>(buf.map(0) + buf.stride(0) * y + x * 2);
*p = color.argb1555();
break;
}
@@ -114,9 +114,9 @@ void draw_yuv444_pixel(IFramebuffer& buf, unsigned x, unsigned y, YUV yuv)
if (x >= buf.width() || y >= buf.height())
throw runtime_error("attempt to draw outside the buffer");
- uint8_t* py = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x);
- uint8_t* pu = (uint8_t*)(buf.map(1) + buf.stride(1) * y + x);
- uint8_t* pv = (uint8_t*)(buf.map(2) + buf.stride(2) * y + x);
+ uint8_t* py = reinterpret_cast<uint8_t*>(buf.map(0) + buf.stride(0) * y + x);
+ uint8_t* pu = reinterpret_cast<uint8_t*>(buf.map(1) + buf.stride(1) * y + x);
+ uint8_t* pv = reinterpret_cast<uint8_t*>(buf.map(2) + buf.stride(2) * y + x);
switch (buf.format()) {
case PixelFormat::YUV444:
@@ -139,7 +139,7 @@ void draw_yuv444_pixel(IFramebuffer& buf, unsigned x, unsigned y, YUV yuv)
static void draw_yuv422_packed_macropixel(IFramebuffer& buf, unsigned x, unsigned y,
YUV yuv1, YUV yuv2)
{
- uint8_t* p = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x * 2);
+ uint8_t* p = reinterpret_cast<uint8_t*>(buf.map(0) + buf.stride(0) * y + x * 2);
uint8_t y0 = yuv1.y;
uint8_t y1 = yuv2.y;
@@ -184,7 +184,7 @@ static void draw_y2xx_packed_macropixel(IFramebuffer& buf, unsigned x, unsigned
YUV yuv1, YUV yuv2)
{
const uint32_t macro_size = 4;
- uint16_t* p = (uint16_t*)(buf.map(0) + buf.stride(0) * y + x * macro_size);
+ uint16_t* p = reinterpret_cast<uint16_t*>(buf.map(0) + buf.stride(0) * y + x * macro_size);
switch (buf.format()) {
case PixelFormat::Y210: {
@@ -239,8 +239,8 @@ static void draw_y2xx_packed_macropixel(IFramebuffer& buf, unsigned x, unsigned
static void draw_yuv422_semiplanar_macropixel(IFramebuffer& buf, unsigned x, unsigned y,
YUV yuv1, YUV yuv2)
{
- uint8_t* py = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x);
- uint8_t* puv = (uint8_t*)(buf.map(1) + buf.stride(1) * y + x);
+ uint8_t* py = reinterpret_cast<uint8_t*>(buf.map(0) + buf.stride(0) * y + x);
+ uint8_t* puv = reinterpret_cast<uint8_t*>(buf.map(1) + buf.stride(1) * y + x);
uint8_t y0 = yuv1.y;
uint8_t y1 = yuv2.y;
@@ -270,9 +270,9 @@ static void draw_yuv422_semiplanar_macropixel(IFramebuffer& buf, unsigned x, uns
static void draw_yuv422_planar_macropixel(IFramebuffer& buf, unsigned x, unsigned y,
YUV yuv1, YUV yuv2)
{
- uint8_t* py = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x);
- uint8_t* pu = (uint8_t*)(buf.map(1) + buf.stride(1) * y + x / 2);
- uint8_t* pv = (uint8_t*)(buf.map(2) + buf.stride(2) * y + x / 2);
+ uint8_t* py = reinterpret_cast<uint8_t*>(buf.map(0) + buf.stride(0) * y + x);
+ uint8_t* pu = reinterpret_cast<uint8_t*>(buf.map(1) + buf.stride(1) * y + x / 2);
+ uint8_t* pv = reinterpret_cast<uint8_t*>(buf.map(2) + buf.stride(2) * y + x / 2);
uint8_t y0 = yuv1.y;
uint8_t y1 = yuv2.y;
@@ -338,10 +338,10 @@ void draw_yuv422_macropixel(IFramebuffer& buf, unsigned x, unsigned y, YUV yuv1,
static void draw_yuv420_semiplanar_macropixel(IFramebuffer& buf, unsigned x, unsigned y,
YUV yuv1, YUV yuv2, YUV yuv3, YUV yuv4)
{
- uint8_t* py1 = (uint8_t*)(buf.map(0) + buf.stride(0) * (y + 0) + x);
- uint8_t* py2 = (uint8_t*)(buf.map(0) + buf.stride(0) * (y + 1) + x);
+ uint8_t* py1 = reinterpret_cast<uint8_t*>(buf.map(0) + buf.stride(0) * (y + 0) + x);
+ uint8_t* py2 = reinterpret_cast<uint8_t*>(buf.map(0) + buf.stride(0) * (y + 1) + x);
- uint8_t* puv = (uint8_t*)(buf.map(1) + buf.stride(1) * (y / 2) + x);
+ uint8_t* puv = reinterpret_cast<uint8_t*>(buf.map(1) + buf.stride(1) * (y / 2) + x);
uint8_t y0 = yuv1.y;
uint8_t y1 = yuv2.y;
@@ -377,11 +377,11 @@ static void draw_yuv420_semiplanar_macropixel(IFramebuffer& buf, unsigned x, uns
static void draw_yuv420_planar_macropixel(IFramebuffer& buf, unsigned x, unsigned y,
YUV yuv1, YUV yuv2, YUV yuv3, YUV yuv4)
{
- uint8_t* py1 = (uint8_t*)(buf.map(0) + buf.stride(0) * (y + 0) + x);
- uint8_t* py2 = (uint8_t*)(buf.map(0) + buf.stride(0) * (y + 1) + x);
+ uint8_t* py1 = reinterpret_cast<uint8_t*>(buf.map(0) + buf.stride(0) * (y + 0) + x);
+ uint8_t* py2 = reinterpret_cast<uint8_t*>(buf.map(0) + buf.stride(0) * (y + 1) + x);
- uint8_t* pu = (uint8_t*)(buf.map(1) + buf.stride(1) * (y / 2) + x / 2);
- uint8_t* pv = (uint8_t*)(buf.map(2) + buf.stride(2) * (y / 2) + x / 2);
+ uint8_t* pu = reinterpret_cast<uint8_t*>(buf.map(1) + buf.stride(1) * (y / 2) + x / 2);
+ uint8_t* pv = reinterpret_cast<uint8_t*>(buf.map(2) + buf.stride(2) * (y / 2) + x / 2);
uint8_t y0 = yuv1.y;
uint8_t y1 = yuv2.y;