From: Vinson Lee Date: Sat, 28 Sep 2013 05:42:58 +0000 (-0700) Subject: util/u_format: Assert that format block size is at least 1 byte. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ac82495d6d562091d819b0109adf43fd89e49537;p=mesa.git util/u_format: Assert that format block size is at least 1 byte. The block size for all formats is currently at least 1 byte. Add an assertion for this. This should silence several Coverity "Division or modulo by zero" defects. Signed-off-by: Vinson Lee Reviewed-by: Brian Paul --- diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h index 28527f532ad..84f16d503d7 100644 --- a/src/gallium/auxiliary/util/u_format.h +++ b/src/gallium/auxiliary/util/u_format.h @@ -716,10 +716,15 @@ static INLINE uint util_format_get_blocksize(enum pipe_format format) { uint bits = util_format_get_blocksizebits(format); + uint bytes = bits / 8; assert(bits % 8 == 0); + assert(bytes > 0); + if (bytes == 0) { + bytes = 1; + } - return bits / 8; + return bytes; } static INLINE uint