Merge lp:~mc-return/unity/unity.merge-fix1131152-cppcheck-issues into lp:unity

Proposed by MC Return
Status: Merged
Approved by: Andrea Azzarone
Approved revision: no longer in the source branch.
Merged at revision: 3168
Proposed branch: lp:~mc-return/unity/unity.merge-fix1131152-cppcheck-issues
Merge into: lp:unity
Diff against target: 54 lines (+5/-6)
4 files modified
plugins/unityshell/src/unity-util-accessible.cpp (+1/-0)
shortcuts/ShortcutHintPrivate.cpp (+2/-4)
unity-shared/DashStyle.cpp (+1/-2)
unity-shared/LayoutSystem.cpp (+1/-0)
To merge this branch: bzr merge lp:~mc-return/unity/unity.merge-fix1131152-cppcheck-issues
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+149801@code.launchpad.net

Commit message

Fixed some issues reported by cppcheck:

* Hopefully fixed memory leak of atk_event.

* size_t index is always unsigned, so the check if it is >= 0
  is redundant and can be removed.
  The else branch will never be executed so it can be removed
  as well.

* Do not assign true to bool odd, because this value is never used.
  Instead declare and assign the value in one line.

* Also initialize the struct LayoutWindow member variable float alpha
  with 0.0f in the LayoutWindow::LayoutWindow(Window xid) constructor.

(LP: #1131152)

Description of the change

Problems reported by cppcheck:

[unity-shared/LayoutSystem.cpp:261]: (warning) Member variable 'LayoutWindow::alpha' is not initialized in the constructor.

[unity-shared/DashStyle.cpp:981] -> [unity-shared/DashStyle.cpp:983]: (performance) Variable 'odd' is reassigned a value before the old one has been used.

[shortcuts/ShortcutHintPrivate.cpp:38]: (style) Unsigned variable 'index' can't be negative so it is unnecessary to test it.

[plugins/unityshell/src/unity-util-accessible.cpp:289]: (error) Memory leak: atk_event

Note:
This MP does not contain any logic changes, so the function GetMetaKey(std::string const& scut) in shortcuts/ShortcutHintPrivate.cpp for example never returned "" before and this behaviour will not change when merging this.

To post a comment you must log in.
Revision history for this message
Andrea Azzarone (azzar1) :
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/unity-util-accessible.cpp'
2--- plugins/unityshell/src/unity-util-accessible.cpp 2012-01-04 01:54:41 +0000
3+++ plugins/unityshell/src/unity-util-accessible.cpp 2013-02-21 12:04:22 +0000
4@@ -286,6 +286,7 @@
5 /* we don't call atk_key_event_from_nux_event_key if the event
6 is different to keydown or keyup */
7 g_assert_not_reached();
8+ g_free(atk_event);
9 return NULL;
10 }
11
12
13=== modified file 'shortcuts/ShortcutHintPrivate.cpp'
14--- shortcuts/ShortcutHintPrivate.cpp 2012-10-18 11:45:32 +0000
15+++ shortcuts/ShortcutHintPrivate.cpp 2013-02-21 12:04:22 +0000
16@@ -35,10 +35,8 @@
17 std::string GetMetaKey(std::string const& scut)
18 {
19 size_t index = scut.find_last_of( ">");
20- if (index >= 0)
21- return std::string(scut.begin(), scut.begin() + index + 1);
22- else
23- return "";
24+
25+ return std::string(scut.begin(), scut.begin() + index + 1);
26 }
27
28 std::string FixShortcutFormat(std::string const& scut)
29
30=== modified file 'unity-shared/DashStyle.cpp'
31--- unity-shared/DashStyle.cpp 2013-01-30 09:16:58 +0000
32+++ unity-shared/DashStyle.cpp 2013-02-21 12:04:22 +0000
33@@ -978,9 +978,8 @@
34 Segment segment)
35 {
36 double radius = cornerRadius / aspect;
37- bool odd = true;
38
39- odd = cairo_get_line_width (cr) == 2.0 ? false : true;
40+ bool odd = cairo_get_line_width (cr) == 2.0 ? false : true;
41
42 switch (segment)
43 {
44
45=== modified file 'unity-shared/LayoutSystem.cpp'
46--- unity-shared/LayoutSystem.cpp 2012-11-13 19:16:59 +0000
47+++ unity-shared/LayoutSystem.cpp 2013-02-21 12:04:22 +0000
48@@ -264,6 +264,7 @@
49 , decoration_height(0)
50 , selected(false)
51 , aspect_ratio(geo.width / static_cast<float>(geo.height))
52+ , alpha(0.0f)
53 {
54 auto& wm = WindowManager::Default();
55