rendernode-tool: Fix array size
authorBenjamin Otte <otte@redhat.com>
Sun, 27 Aug 2023 19:02:03 +0000 (21:02 +0200)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 19 Sep 2023 20:32:27 +0000 (16:32 -0400)
Also add an assertion, so things explode properly if we forget to
update the array size when adding new nodes, instead of writing random
memory.

tools/gtk-rendernode-tool-info.c

index 3e4a9d1738fa1e19a352632d02e5726cbf51f8e2..482f53e117ffbcf946e6a1e028319c8d2abc36ae 100644 (file)
@@ -29,6 +29,7 @@
 #include <gtk/gtk.h>
 #include "gtk-rendernode-tool.h"
 
+#define N_NODE_TYPES (GSK_MASK_NODE + 1)
 static void
 count_nodes (GskRenderNode *node,
              unsigned int  *counts,
@@ -37,6 +38,7 @@ count_nodes (GskRenderNode *node,
   unsigned int d, dd;
 
   counts[gsk_render_node_get_node_type (node)] += 1;
+  g_assert (gsk_render_node_get_node_type (node) < N_NODE_TYPES);
   d = 0;
 
   switch (gsk_render_node_get_node_type (node))
@@ -157,7 +159,7 @@ static void
 file_info (const char *filename)
 {
   GskRenderNode *node;
-  unsigned int counts[GSK_MASK_NODE + 1] = { 0, };
+  unsigned int counts[N_NODE_TYPES] = { 0, };
   unsigned int total = 0;
   unsigned int namelen = 0;
   unsigned int depth = 0;