cogl-material-arbfp: Use separate buffers when calling g_ascii_dtostr
authorNeil Roberts <neil@linux.intel.com>
Sat, 17 Jul 2010 11:40:19 +0000 (12:40 +0100)
committerEmmanuele Bassi <ebassi@linux.intel.com>
Sun, 18 Jul 2010 10:01:05 +0000 (11:01 +0100)
g_ascii_dtostr was being used in four separate arguments to
g_string_append_printf but all invocations of it were using the same
buffer. This would end up with all of the arguments having the same
value which would depend on whichever order the compiler evaluates
them in. This patches changes it to use a multi-dimensional array and
a loop to fill in the separate buffers.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2219

clutter/cogl/cogl/cogl-material-arbfp.c

index 1eb6c68..50297f0 100644 (file)
@@ -525,24 +525,25 @@ setup_arg (CoglMaterial *material,
         CoglMaterialLayer *authority =
           _cogl_material_layer_get_authority (layer, state);
         CoglMaterialLayerBigState *big_state = authority->big_state;
-        char buf[G_ASCII_DTOSTR_BUF_SIZE];
+        char buf[4][G_ASCII_DTOSTR_BUF_SIZE];
+        int i;
 
         arg->type = COGL_MATERIAL_BACKEND_ARBFP_ARG_TYPE_CONSTANT;
         arg->name = "constant%d";
         arg->constant_id = priv->next_constant_id++;
 
+        for (i = 0; i < 4; i++)
+          g_ascii_dtostr (buf[i], G_ASCII_DTOSTR_BUF_SIZE,
+                          big_state->texture_combine_constant[i]);
+
         g_string_append_printf (priv->source,
                                 "PARAM constant%d = "
                                 "  {%s, %s, %s, %s};\n",
                                 arg->constant_id,
-                                g_ascii_dtostr (buf, sizeof (buf),
-                                                big_state->texture_combine_constant[0]),
-                                g_ascii_dtostr (buf, sizeof (buf),
-                                                big_state->texture_combine_constant[1]),
-                                g_ascii_dtostr (buf, sizeof (buf),
-                                                big_state->texture_combine_constant[2]),
-                                g_ascii_dtostr (buf, sizeof (buf),
-                                                big_state->texture_combine_constant[3]));
+                                buf[0],
+                                buf[1],
+                                buf[2],
+                                buf[3]);
         break;
       }
     case GL_PRIMARY_COLOR: