gallium/util: widen type before multiplication
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Tue, 13 Aug 2019 11:02:24 +0000 (13:02 +0200)
committerErik Faye-Lund <erik.faye-lund@collabora.com>
Thu, 15 Aug 2019 18:23:53 +0000 (20:23 +0200)
This method returns size_t, but the multiplication multiplies two
integers, leading to overflow rather than type widening.

Noticed by compiling with MSVC, which emits a warning.

Signed-off-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/gallium/auxiliary/util/u_format.h

index fe348aa55c8f6b67a33e063d5842d269a4e44655..eb8c2f6ae3fee719f8470513611b4714243afbb0 100644 (file)
@@ -870,7 +870,7 @@ static inline size_t
 util_format_get_stride(enum pipe_format format,
                        unsigned width)
 {
-   return util_format_get_nblocksx(format, width) * util_format_get_blocksize(format);
+   return (size_t)util_format_get_nblocksx(format, width) * util_format_get_blocksize(format);
 }
 
 static inline size_t