Merge lp:~ted/libdbusmenu/null-protect-when-set into lp:libdbusmenu/0.5

Proposed by Ted Gould
Status: Merged
Merged at revision: 221
Proposed branch: lp:~ted/libdbusmenu/null-protect-when-set
Merge into: lp:libdbusmenu/0.5
Diff against target: 60 lines (+26/-23)
1 file modified
libdbusmenu-glib/menuitem.c (+26/-23)
To merge this branch: bzr merge lp:~ted/libdbusmenu/null-protect-when-set
Reviewer Review Type Date Requested Status
Conor Curran (community) Approve
Review via email: mp+50977@code.launchpad.net

Description of the change

Don't check on the default anything if the incomming value is NULL.

To post a comment you must log in.
Revision history for this message
Conor Curran (cjcurran) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libdbusmenu-glib/menuitem.c'
2--- libdbusmenu-glib/menuitem.c 2011-02-22 03:41:54 +0000
3+++ libdbusmenu-glib/menuitem.c 2011-02-23 19:30:25 +0000
4@@ -1025,31 +1025,34 @@
5 g_return_val_if_fail(property != NULL, FALSE);
6
7 DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi);
8-
9- const gchar * type = menuitem_get_type(mi);
10-
11- /* Check the expected type to see if we want to have a warning */
12- GVariantType * default_type = dbusmenu_defaults_default_get_type(priv->defaults, type, property);
13- if (default_type != NULL) {
14- /* If we have an expected type we should check to see if
15- the value we've been given is of the same type and generate
16- a warning if it isn't */
17- if (!g_variant_is_of_type(value, default_type)) {
18- g_warning("Setting menuitem property '%s' with value of type '%s' when expecting '%s'", property, g_variant_get_type_string(value), g_variant_type_peek_string(default_type));
19+ GVariant * default_value = NULL;
20+
21+ if (value != NULL) {
22+ const gchar * type = menuitem_get_type(mi);
23+
24+ /* Check the expected type to see if we want to have a warning */
25+ GVariantType * default_type = dbusmenu_defaults_default_get_type(priv->defaults, type, property);
26+ if (default_type != NULL) {
27+ /* If we have an expected type we should check to see if
28+ the value we've been given is of the same type and generate
29+ a warning if it isn't */
30+ if (!g_variant_is_of_type(value, default_type)) {
31+ g_warning("Setting menuitem property '%s' with value of type '%s' when expecting '%s'", property, g_variant_get_type_string(value), g_variant_type_peek_string(default_type));
32+ }
33 }
34- }
35
36- /* Check the defaults database to see if we have a default
37- for this property. */
38- GVariant * default_value = dbusmenu_defaults_default_get(priv->defaults, type, property);
39- if (default_value != NULL) {
40- /* Now see if we're setting this to the same value as the
41- default. If we are then we just want to swallow this variant
42- and make the function behave like we're clearing it. */
43- if (g_variant_equal(default_value, value)) {
44- g_variant_ref_sink(value);
45- g_variant_unref(value);
46- value = NULL;
47+ /* Check the defaults database to see if we have a default
48+ for this property. */
49+ default_value = dbusmenu_defaults_default_get(priv->defaults, type, property);
50+ if (default_value != NULL) {
51+ /* Now see if we're setting this to the same value as the
52+ default. If we are then we just want to swallow this variant
53+ and make the function behave like we're clearing it. */
54+ if (g_variant_equal(default_value, value)) {
55+ g_variant_ref_sink(value);
56+ g_variant_unref(value);
57+ value = NULL;
58+ }
59 }
60 }
61

Subscribers

People subscribed via source and target branches