GNOME Bugzilla – Bug 752052
appsrc: Initialize min and max vars in get_property() for fix compiler warnings
Last modified: 2016-12-25 13:21:59 UTC
Created attachment 306981 [details] [review] patch gstappsrc: Initializing min and max in gst_app_src_get_property This gets rid of this compiler message: gstappsrc.c: In function 'gst_app_src_get_property': gstappsrc.c:741:7: error: 'max' may be used uninitialized in this function [-Werror=maybe-uninitialized] g_value_set_int64 (value, max); ^ gstappsrc.c:733:7: error: 'min' may be used uninitialized in this function [-Werror=maybe-uninitialized] g_value_set_int64 (value, min); ^ GCC's analysis is correct. If appsrc is not GST_IS_APP_SRC, then gst_app_src_get_latency will return without setting min and max.
Review of attachment 306981 [details] [review]: Actually, this case should never really happen. Add some g_return_if_fail() at the top of get_property().
(In reply to Sebastian Dröge (slomo) from comment #1) > Add some g_return_if_fail() at the top of get_property(). I'm afraid that this doesn't make the compiler happy. The only thing that I could get to work is this: GstAppSrc *appsrc = GST_APP_SRC_CAST (object); GstAppSrcPrivate *priv = appsrc->priv; //g_return_if_fail (GST_IS_APP_SRC (object)); //g_return_if_fail (GST_IS_APP_SRC (appsrc)); if (!GST_IS_APP_SRC (object)) return; else if (!GST_IS_APP_SRC (appsrc)) return; else switch (prop_id) { case PROP_CAPS: ... note the two if statements. I don't understand why GCC requires both. Also note that g_return_if_fail does not seem to get us anything. I guess this is because it is a macro which can compile to (void)0;. But I'm only guessing. An easy way out is to assume that GCC is just wrong and to ignore this bug report. But I'd be careful assuming that...
Are you compiling with -DG_DISABLE_CHECKS or somesuch?
Thanks for the bug report and the patch! > An easy way out is to assume that GCC is just wrong and to ignore > this bug report. But I'd be careful assuming that... GCC is most certainly wrong in this case, but it can't know that here. This is a GObject vfunc, so we can be fairly sure that this really is a GstAppSrc. IS_APP_SRC checks in get/set_property funcs don't really make sense IMHO and I tend to remove them whenever I see them. Since we compile with -Werror we just need to work around these false-positives as we do in other places. commit 57ff3ea72fd30fa900c069bb948745f3bfdff9d1 Author: Tobias Mueller <muelli@cryptobitch.de> Date: Thu Jul 2 07:23:23 2015 +0200 appsrc: fix compiler warning Initialize min and max _get_property() to gets rid of these compiler warnings: gstappsrc.c:741:7: error: 'max' may be used uninitialized in this function g_value_set_int64 (value, max); ^ gstappsrc.c:733:7: error: 'min' may be used uninitialized in this function g_value_set_int64 (value, min); ^ Which happens because gcc doesn't know that GST_IS_APP_SRC will never fail here. https://bugzilla.gnome.org/show_bug.cgi?id=752052