Merge lp:~3v1n0/unity/fix-keyboardutil-crash-920258-5.0 into lp:unity/5.0

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 2384
Proposed branch: lp:~3v1n0/unity/fix-keyboardutil-crash-920258-5.0
Merge into: lp:unity/5.0
Diff against target: 68 lines (+12/-7)
2 files modified
plugins/unityshell/src/KeyboardUtil.cpp (+11/-6)
plugins/unityshell/src/KeyboardUtil.h (+1/-1)
To merge this branch: bzr merge lp:~3v1n0/unity/fix-keyboardutil-crash-920258-5.0
Reviewer Review Type Date Requested Status
Gord Allott (community) Approve
Review via email: mp+113659@code.launchpad.net

Commit message

KeyboardUtil: fix possible crash if XkbGetKeyboard returns null

Also use initializer list

Description of the change

To post a comment you must log in.
Revision history for this message
Gord Allott (gordallott) wrote :

solid code.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/KeyboardUtil.cpp'
2--- plugins/unityshell/src/KeyboardUtil.cpp 2012-06-28 08:49:20 +0000
3+++ plugins/unityshell/src/KeyboardUtil.cpp 2012-07-05 23:01:20 +0000
4@@ -25,17 +25,18 @@
5
6 namespace unity {
7 namespace ui {
8+namespace {
9+ const unsigned int FETCH_MASK = XkbGBN_KeyNamesMask | XkbGBN_ClientSymbolsMask | XkbGBN_GeometryMask;
10+}
11
12 KeyboardUtil::KeyboardUtil(Display *display)
13 : display_(display)
14-{
15- unsigned int fetch_mask = XkbGBN_KeyNamesMask | XkbGBN_ClientSymbolsMask | XkbGBN_GeometryMask;
16- keyboard_ = XkbGetKeyboard (display, fetch_mask, XkbUseCoreKbd);
17-}
18+ , keyboard_(XkbGetKeyboard(display_, FETCH_MASK, XkbUseCoreKbd))
19+{}
20
21 KeyboardUtil::~KeyboardUtil()
22 {
23- XkbFreeKeyboard (keyboard_, 0, True);
24+ XkbFreeKeyboard(keyboard_, 0, True);
25 }
26
27 bool KeyboardUtil::FindKeyInGeometry(XkbGeometryPtr geo, char *key_name, int& res_section, XkbBoundsRec& res_bounds) const
28@@ -86,6 +87,9 @@
29
30 guint KeyboardUtil::ConvertKeyToKeycode(XkbKeyPtr key) const
31 {
32+ if (!keyboard_)
33+ return 0;
34+
35 int min_code = keyboard_->min_key_code;
36 int max_code = keyboard_->max_key_code;
37
38@@ -94,6 +98,7 @@
39 if (!strncmp(key->name.name, keyboard_->names->keys[i].name, XkbKeyNameLength))
40 return i;
41 }
42+
43 return 0;
44 }
45
46@@ -186,7 +191,7 @@
47
48 int code = XKeysymToKeycode(display_, key_symbol);
49
50- if (!code)
51+ if (!code || !keyboard_)
52 return result;
53
54 if (keyboard_->min_key_code > code || keyboard_->max_key_code < code)
55
56=== modified file 'plugins/unityshell/src/KeyboardUtil.h'
57--- plugins/unityshell/src/KeyboardUtil.h 2012-06-28 08:49:20 +0000
58+++ plugins/unityshell/src/KeyboardUtil.h 2012-07-05 23:01:20 +0000
59@@ -51,8 +51,8 @@
60
61 XkbBoundsRec GetAbsoluteKeyBounds (XkbKeyPtr key, XkbRowPtr row, XkbSectionPtr section, XkbGeometryPtr geo) const;
62
63+ Display *display_;
64 XkbDescPtr keyboard_;
65- Display *display_;
66 };
67
68 }

Subscribers

People subscribed via source and target branches