GNOME Bugzilla – Bug 738585
[review] dcbw/keyfile-enum-flags: fix enum/flags types after libnm-core property changes
Last modified: 2014-11-07 15:23:09 UTC
When some properties got converted to G_TYPE_ENUM and G_TYPE_FLAGS the keyfile plugin was not updated to handle these types.
Looks good. I was confused by this comment: >+ /* Flags are 32-bit but GKeyFile only has uint64 functions */ until I realized you meant "doesn't have uint32 functions", not "has no 32-bit integer functions"
+ if (uint_val <= G_MAXUINT32) + g_object_set (setting, key, uint_val, NULL); Are you sure that the maximum is G_MAXUINT32? I think it's G_MAXUINT. I think, you also need a cast: + g_object_set (setting, key, (guint) uint_val, NULL); same later, just to make it explicit: + g_object_set (setting, key, (gint) int_val, NULL); And I think, that glib still checks the integer value against the min/max values, and g_returns on out-of-range. Hence, invalid configurations can easily trigger a g_critical() by setting uint_val to a out-of-range value. But the same already applies to other integer types... Interesting, that no existing tests caught this error... Rest looks good to me.
(In reply to comment #2) > + if (uint_val <= G_MAXUINT32) > + g_object_set (setting, key, uint_val, NULL); > > Are you sure that the maximum is G_MAXUINT32? I think it's G_MAXUINT. > I think, you also need a cast: > + g_object_set (setting, key, (guint) uint_val, NULL); Fixed. > same later, just to make it explicit: > + g_object_set (setting, key, (gint) int_val, NULL); Fixed. > And I think, that glib still checks the integer value against the min/max > values, and g_returns on out-of-range. Hence, invalid configurations can easily > trigger a g_critical() by setting uint_val to a out-of-range value. But the > same already applies to other integer types... Yeah, it does: g_enum_class_init(): class->minimum = class->values->value; class->maximum = class->values->value; for (values = class->values; values->value_name; values++) { class->minimum = MIN (class->minimum, values->value); class->maximum = MAX (class->maximum, values->value); class->n_values++; } g_flags_class_init(): for (values = class->values; values->value_name; values++) { class->mask |= values->value; class->n_values++; } > Interesting, that no existing tests caught this error... Yeah, we never tested the properties that would have triggered it. Fixed the code comments per danw and merged to master.