[Mesa-dev] [PATCH 08/13] mesa: In emit_texenv() type mismatch was forced with typecast
Matt Turner
mattst88 at gmail.com
Wed Mar 12 15:11:24 PDT 2014
On Wed, Mar 12, 2014 at 2:11 PM, Juha-Pekka Heikkila
<juhapekka.heikkila at gmail.com> wrote:
> Type mismatch caused random memory to be copied when casted
> memory area was smaller than expected type.
>
> Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
> ---
> src/mesa/main/ff_fragment_shader.cpp | 17 +++++++++--------
> 1 file changed, 9 insertions(+), 8 deletions(-)
>
> diff --git a/src/mesa/main/ff_fragment_shader.cpp b/src/mesa/main/ff_fragment_shader.cpp
> index cad67aa..3e00424 100644
> --- a/src/mesa/main/ff_fragment_shader.cpp
> +++ b/src/mesa/main/ff_fragment_shader.cpp
> @@ -888,14 +888,15 @@ emit_texenv(texenv_fragment_program *p, GLuint unit)
> shift = new(p->mem_ctx) ir_constant((float)(1 << rgb_shift));
> }
> else {
> - float const_data[4] = {
> - float(1 << rgb_shift),
> - float(1 << rgb_shift),
> - float(1 << rgb_shift),
> - float(1 << alpha_shift)
> - };
> - shift = new(p->mem_ctx) ir_constant(glsl_type::vec4_type,
> - (ir_constant_data *)const_data);
> + ir_constant_data const_data = { .f = {
> + float(1 << rgb_shift),
> + float(1 << rgb_shift),
> + float(1 << rgb_shift),
> + float(1 << alpha_shift)
> + } };
Huh. I'm confused. I thought C++ didn't allow designated initializers.
gcc accepts it here, and only warns with -pedantic:
warning: ISO C++ does not allow C99 designated initializers [-Wpedantic]
Maybe it's just that MSVC doesn't support them? Google is telling me
that the only way to initialize a union in C++ is by initializing its
first field.
In the case that we can actually use designated initializers, Let's
indent this like so:
ir_constant_data const_data = {
.f = {
float(1 << rgb_shift),
float(1 << rgb_shift),
float(1 << rgb_shift),
float(1 << alpha_shift)
}
};
(and hope gmail doesn't mess that up.)
More information about the mesa-dev
mailing list