GNOME Bugzilla – Bug 723530
cogl-pipeline: SEGV in _cogl_pipeline_fragend_glsl_end
Last modified: 2014-02-20 13:49:06 UTC
https://git.gnome.org/browse/cogl/tree/cogl/driver/gl/cogl-pipeline-fragend-glsl.c#n1011 Should initialize layer_data to NULL. It may not cause SEGV depends on compilers, but the compiler does give a warning about "referencing before initializing".
Created attachment 268022 [details] [review] Don't dereference an unitialised pointer in _cogl_container_of The previous implementation was dereferencing the sample pointer in order to get the offset to subtract from the member pointer. The resulting value is then only used to get a pointer to the member in order to calculate the offset so it doesn't actually read from the memory location and shouldn't cause any problems. However this is probably technically invalid and could have undefined behaviour. It looks like clang takes advantage of this undefined behaviour and doesn't actually offset the pointer. It also generates a warning when it does this. This patch splits the _cogl_container_of macro into two implementations. Previously the macro was always used in the list iterator macros like this: SomeType *sample = _cogl_container_of(list_node, sample, link) Instead of doing that there is now a new macro called _cogl_list_set_iterator which explicitly assigns to the sample pointer with an initial value before assigning to it again with the real offset. This redundant initialisation gets optimised out by compiler. The second macro is still called _cogl_container_of but instead of taking a sample pointer it just directly takes the type name. That way it can use the standard offsetof macro.
Comment on attachment 268022 [details] [review] Don't dereference an unitialised pointer in _cogl_container_of Thanks for fixing this, the patch looks good to land to me. Sorry for the delay in replying. Reviewed-by: Robert Bragg <robert@linux.intel.com>
Thanks for the review. I've pushed it to master and the 1.16 and 1.18 branches.