diff options
author | Christophe Fergeau <cfergeau@redhat.com> | 2013-04-09 17:50:50 +0200 |
---|---|---|
committer | Christophe Fergeau <cfergeau@redhat.com> | 2013-04-10 09:53:51 +0200 |
commit | 5ebeee51146f9441474377e77bbc15ec69530d54 (patch) | |
tree | 7558aa8295e6c8cafb631ab665f660222372d063 /common/lz_common.h | |
parent | 5aa31e753f1a073c3039998a677a6e19a8b2cd45 (diff) | |
download | spice-common-5ebeee51146f9441474377e77bbc15ec69530d54.tar.gz spice-common-5ebeee51146f9441474377e77bbc15ec69530d54.tar.xz spice-common-5ebeee51146f9441474377e77bbc15ec69530d54.zip |
Add compile-time check for lz arrays
In addition to Laszlo's commit fixing rhbz#928973, we can add
some compile-time assertion to lz_common.h to help catch similar
bugs in the future.
This uses gnulib's verify.h to make sure at compile-time that
the various constant arrays used in lz_common.h are of the expected
size.
I've checked that before Laszlo's patch, the assert triggers, and
that it's gone after it.
Diffstat (limited to 'common/lz_common.h')
-rw-r--r-- | common/lz_common.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/common/lz_common.h b/common/lz_common.h index 1a2213a..8d4861b 100644 --- a/common/lz_common.h +++ b/common/lz_common.h @@ -24,6 +24,7 @@ #define _LZ_COMMON_H #include <spice/macros.h> +#include "verify.h" SPICE_BEGIN_DECLS @@ -57,6 +58,10 @@ static const int IS_IMAGE_TYPE_RGB[] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1}; static const int PLT_PIXELS_PER_BYTE[] = {0, 8, 8, 2, 2, 1}; static const int RGB_BYTES_PER_PIXEL[] = {0, 1, 1, 1, 1, 1, 2, 3, 4, 4, 4, 1}; +verify(SPICE_N_ELEMENTS(IS_IMAGE_TYPE_PLT) == (LZ_IMAGE_TYPE_A8 + 1)); +verify(SPICE_N_ELEMENTS(IS_IMAGE_TYPE_RGB) == (LZ_IMAGE_TYPE_A8 + 1)); +verify(SPICE_N_ELEMENTS(PLT_PIXELS_PER_BYTE) == (LZ_IMAGE_TYPE_PLT8 + 1)); +verify(SPICE_N_ELEMENTS(RGB_BYTES_PER_PIXEL) == (LZ_IMAGE_TYPE_A8 + 1)); #define LZ_MAGIC (*(uint32_t *)"LZ ") #define LZ_VERSION_MAJOR 1U |