After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 574651 - Incorrect cast between GstState and State&
Incorrect cast between GstState and State&
Status: RESOLVED FIXED
Product: gstreamermm
Classification: Bindings
Component: general
git master
Other Linux
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2009-03-09 15:53 UTC by David King
Modified: 2011-01-16 23:37 UTC
See Also:
GNOME target: ---
GNOME version: 2.25/2.26


Attachments
Patch to fix incorrect casts and use of NULL. (2.51 KB, patch)
2009-03-09 15:54 UTC, David King
none Details | Review
Additionally, initialises GstState to GST_STATE_NULL in parse*() functions. (2.59 KB, patch)
2009-03-09 16:46 UTC, David King
committed Details | Review

Description David King 2009-03-09 15:53:25 UTC
I came across an issue in gstreamermm that caused my code to crash. The code in question utilises the parse() member function of Gst::MessageStateChanged. In gstreamermm, the parse() function dereferences an unitialised pointer. On closer inspection, parse_old() and parse_pending() were also affected, and all three functions were also unnecessarily using NULL and casting to State incorrectly.
Comment 1 David King 2009-03-09 15:54:40 UTC
Created attachment 130335 [details] [review]
Patch to fix incorrect casts and use of NULL.
Comment 2 Murray Cumming 2009-03-09 16:03:42 UTC
Well done. I would add some more initialize in place such as this, in case gstreamer doesn't do it always:

GstState pending_state; //Choose an arbitary initial enum value - maybe GST_STATE_NULL.
gst_message_parse_state_changed(const_cast<GstMessage*>(gobj()), 0,

 
Comment 3 David King 2009-03-09 16:17:12 UTC
(In reply to comment #2)
> Well done. I would add some more initialize in place such as this, in case
> gstreamer doesn't do it always:
> 
> GstState pending_state; //Choose an arbitary initial enum value - maybe
> GST_STATE_NULL.
> gst_message_parse_state_changed(const_cast<GstMessage*>(gobj()), 0,

This is possible, although gst_message_parse_state_changed(), which is called by parse*(), checks each argument as below:

void gst_message_parse_state_changed (GstMessage * message, GstState * oldstate, GstState * newstate, GstState * pending)
{
  g_return_if_fail (GST_IS_MESSAGE (message));
  g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED);

  if (oldstate)
    *oldstate =
        g_value_get_enum (gst_structure_id_get_value (message->structure,
            GST_QUARK (OLD_STATE)));
  /* and so on for other arguments... */
}

Is it therefore redundant to initialise GstState? If not, I will happily revise the patch.
Comment 4 Murray Cumming 2009-03-09 16:31:59 UTC
You should never depend on the implementation. Tomorrow it might be different.
Comment 5 David King 2009-03-09 16:46:45 UTC
Created attachment 130341 [details] [review]
Additionally, initialises GstState to GST_STATE_NULL in parse*() functions.

Yes, I see what you mean about not relying on the implementation.
Comment 6 José Alburquerque 2009-03-09 18:46:42 UTC
Thanks for catching this.  Are the int() casts inside the State() casts necessary?
Comment 7 José Alburquerque 2009-03-09 20:37:09 UTC
Nevermind.  I've committed the patch w/o the int casts (I think they're not needed when converting between Gst::State and GstState).
Comment 8 David King 2009-03-10 11:37:17 UTC
Yes, when casting an enum type to another enum (which has the same range), there is no need to cast to an int explicitly. I had to go and read the C++ standard to check this unusual behaviour, though!
Comment 9 José Alburquerque 2009-03-10 16:13:58 UTC
Its just that its not done through gstreamermm and for a minute I thought it might be necessary to go through the casts of enums to make sure they are right.  Thanks again.