Skip to content

Commit

Permalink
Avoid panicking if keysym() was called with a keycode larger than max…
Browse files Browse the repository at this point in the history
…_keycode
  • Loading branch information
pentamassiv committed Oct 21, 2023
1 parent 060e9e4 commit 5621658
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/x11rb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
keycode.into(),
0,
conn.setup().min_keycode.into(),
conn.setup().max_keycode.into(),
mapping.keysyms_per_keycode,
mapping.keysyms.as_slice(),
);
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,17 @@ pub const NO_SYMBOL: Keysym = Keysym(0);

/// Get the keyboard symbol from a keyboard code and its column.
///
/// `min_keycode` can be retrieved from the X11 setup, and `keysyms_per_keycode` and `keysyms` can be
/// `min_keycode` and `max_keycode` can be retrieved from the X11 setup, and `keysyms_per_keycode` and `keysyms` can be
/// retrieved from the X11 server through the `GetKeyboardMapping` request.
pub fn keysym(
keycode: KeyCode,
mut column: u8,
min_keycode: KeyCode,
max_keycode: KeyCode,
keysyms_per_keycode: u8,
keysyms: &[RawKeysym],
) -> Option<Keysym> {
if column >= keysyms_per_keycode && column > 3 {
if column >= keysyms_per_keycode && column > 3 || keycode > max_keycode {
return None;
}

Expand Down

0 comments on commit 5621658

Please sign in to comment.