Make with_x11_visual take ID instead of a pointer

At the moment, the with_x11_visual function takes a pointer and
immediately dereferences it to get the visual info inside. As it is safe
to pass a null pointer to this function, it is unsound. This commit
replaces the pointer parameter with a visual ID, and then uses that ID
to look up the actual visual under
the X11 setup. As this is what was already practically happening before,
this change shouldn't cause any performance downgrades.

This is a breaking change, but it's done in the name of soundness so it
should be okay. It should be trivial for end users to accommodate it,
as it's just a matter of getting the visual ID from the pointer to the
visual before passing it in.

Signed-off-by: John Nunley <dev@notgull.net>
This commit is contained in:
John Nunley 2023-08-05 14:58:23 -07:00 committed by GitHub
parent 8100a6a584
commit 584aab4cd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 31 deletions

View file

@ -886,6 +886,9 @@ pub enum X11Error {
/// Got an invalid activation token.
InvalidActivationToken(Vec<u8>),
/// Could not find a matching X11 visual for this visualid
NoSuchVisual(xproto::Visualid),
}
impl fmt::Display for X11Error {
@ -902,6 +905,13 @@ impl fmt::Display for X11Error {
"Invalid activation token: {}",
std::str::from_utf8(s).unwrap_or("<invalid utf8>")
),
X11Error::NoSuchVisual(visualid) => {
write!(
f,
"Could not find a matching X11 visual for ID `{:x}`",
visualid
)
}
}
}
}