Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 13f2c07e authored by Ivan Lozano's avatar Ivan Lozano
Browse files

Fix sanitizer in egl_display_t::get.

On integer overflow sanitized builds, uintptr_t(dpy)-1U is causing a
runtime error:

 runtime error: unsigned integer overflow: 0 - 1 cannot be represented in
 type 'unsigned int'

This handles the case where dpy is 0 before the decrement occurs.

Bug: 30969751
Test: Compiles.
Change-Id: Ieafe818addfa09cf5b50e2df8f078296c5e3c759
Merged-In: Ieafe818addfa09cf5b50e2df8f078296c5e3c759
parent a9c7e6d1
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -79,6 +79,10 @@ egl_display_t::~egl_display_t() {
}

egl_display_t* egl_display_t::get(EGLDisplay dpy) {
    if (uintptr_t(dpy) == 0) {
        return nullptr;
    }

    uintptr_t index = uintptr_t(dpy)-1U;
    if (index >= NUM_DISPLAYS || !sDisplay[index].isValid()) {
        return nullptr;