btrfs-progs: don't overflow colors[] in fragments
authorZach Brown <zab@redhat.com>
Mon, 7 Oct 2013 21:43:03 +0000 (14:43 -0700)
committerChris Mason <chris.mason@fusionio.com>
Wed, 16 Oct 2013 12:23:13 +0000 (08:23 -0400)
Stop iteration at the number of elements in the colors[] array when
initializing the elements.  Rather than a magic number.  This was found
by static analysis.

Signed-off-by: Zach Brown <zab@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
btrfs-fragments.c

index 4dd94700ae1af638b8f2d7e9cec404f6c8a84fdd..cedbc57ad25d55b80df2232044be3527157614e5 100644 (file)
@@ -283,7 +283,7 @@ list_fragments(int fd, u64 flags, char *dir)
                                white = gdImageColorAllocate(im, 255, 255, 255);
                                black = gdImageColorAllocate(im, 0, 0, 0);  
 
-                               for (j = 0; j < 10; ++j)
+                               for (j = 0; j < ARRAY_SIZE(colors); ++j)
                                        colors[j] = black;
 
                                init_colors(im, colors);