Cast via uintptr_t when converting between integers and pointers

When casting from integer to pointer, promoting the integer to (u)intptr_t
will ensure that the resulting type can be converted to a pointer without
problems. These two casts changed in this commit trigger a warning when
building for CHERI-enabled architectures such as Arm Morello. This is not
just limited to CHERI, the cast from xcb_pixmap_t (uint32_t) to void*
should also be flagged by -Wint-to-void-pointer-cast when using Clang,
however, it appears that warning only handles C-style casts, and not
reinterpret_cast (https://github.com/llvm/llvm-project/issues/53964).
This commit is contained in:
Alex Richardson 2022-02-20 21:18:35 +00:00 committed by Alex Richardson
parent dd6d0b22cc
commit 24eee2df7c
2 changed files with 6 additions and 3 deletions

View file

@ -225,7 +225,7 @@ EGLSurface EglOnXBackend::createSurface(xcb_window_t window)
// a c style cast as there are (buggy) platforms where the size of the Window
// type is not the same as the size of EGLNativeWindowType, reinterpret_cast<>()
// may not compile.
surface = eglCreateWindowSurface(eglDisplay(), config(), (EGLNativeWindowType) nativeWindow, nullptr);
surface = eglCreateWindowSurface(eglDisplay(), config(), (EGLNativeWindowType)(uintptr_t)nativeWindow, nullptr);
}
return surface;

View file

@ -228,8 +228,11 @@ bool EglPixmapTexturePrivate::create(SurfacePixmapX11 *pixmap)
EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
EGL_NONE
};
m_image = eglCreateImageKHR(m_backend->eglDisplay(), EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR,
reinterpret_cast<EGLClientBuffer>(nativePixmap), attribs);
m_image = eglCreateImageKHR(m_backend->eglDisplay(),
EGL_NO_CONTEXT,
EGL_NATIVE_PIXMAP_KHR,
reinterpret_cast<EGLClientBuffer>(static_cast<uintptr_t>(nativePixmap)),
attribs);
if (EGL_NO_IMAGE_KHR == m_image) {
qCDebug(KWIN_CORE) << "failed to create egl image";