GNOME Bugzilla – Bug 675890
Passing NULL buffer to clutter_text_set_text() will not reset the buffer and segfault
Last modified: 2012-05-21 10:35:03 UTC
Created attachment 213874 [details] [review] Fix for passing NULL buffer to clutter_text_set_text() As specified in the documentation, passing a NULL pointer to clutter_text_set_text() should behave the same way as passing an empty string "". This was working as expected previously, but somehow the behaviour changed at some point and creates 2 issues: - Passing NULL as a buffer will not reset the string - If the ClutterText is editable, it will segfault in strcmp I've attached a proposed patch.
Review of attachment 213874 [details] [review]: thanks for the patch. looks good, with one minor change. could you also attach a git formatted patch with a commit message, i.e., use git format-patch to generate the patch? you can also use the git-bz tool. this way we can credit you properly, and apply the patch immediately. thanks again. ::: clutter-git/clutter/clutter-text.c @@ +4768,3 @@ if (self->priv->editable) { + if (strcmp (clutter_text_buffer_get_text (get_buffer (self)), text ? text : "") == 0) instead of the ternary operator, you can use g_strcmp0(), which is provided by GLib to be NULL-safe: g_strcmp0 (clutter_texture_buffer_get_text (get_buffer (self)), text) == 0 this keeps the condition short and readable.
Created attachment 213883 [details] [review] ClutterText: Cannot pass NULL string to clutter_text_set_text() Passing a NULL buffer to clutter_text_set_text() does not behave the same way as passing an empty string "" (as specified in the documentation). This was working as expected previously, but somehow the behaviour changed at some point and created 2 new issues: - Passing a NULL pointer will not reset the string - If the ClutterText is editable, it will segfault in strcmp Validations have been added to prevent this.
Ok, sent this using git-bz. Since it's the first time I use it, let me know if something is off.
Review of attachment 213883 [details] [review]: stellar. thanks for the patch!
Attachment 213883 [details] pushed as a2d40fc - ClutterText: Cannot pass NULL string to clutter_text_set_text()