gallium/auxiliary: Handle count == 0 in u_vbuf_get_minmax_index_mapped
authorIcecream95 <ixn@keemail.me>
Wed, 11 Dec 2019 08:08:41 +0000 (21:08 +1300)
committerMarge Bot <eric+marge@anholt.net>
Mon, 16 Dec 2019 22:57:35 +0000 (22:57 +0000)
This makes u_vbuf_get_minmax_index_mapped return min = 0 / max = 0
when info->count == 0.

That should never happen anyway, but this commit makes it at least
return a sane value that callers expect, and also allows us - and
GCC - to assume count != 0 for optimization purposes.

Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3050>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3050>

src/gallium/auxiliary/util/u_vbuf.c

index 40bdf1ed8308926b2015aa4916c99bb1dcf921c0..7f4248fa49ce96247eb8579342b9c01c2b44eaf1 100644 (file)
@@ -1030,6 +1030,12 @@ u_vbuf_get_minmax_index_mapped(const struct pipe_draw_info *info,
                                const void *indices, unsigned *out_min_index,
                                unsigned *out_max_index)
 {
+   if (!info->count) {
+      *out_min_index = 0;
+      *out_max_index = 0;
+      return;
+   }
+
    switch (info->index_size) {
    case 4: {
       const unsigned *ui_indices = (const unsigned*)indices;