diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-01-02 09:19:55 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-01-02 09:19:55 +0400 |
commit | 0d95dde79b3ed6b0e6ea375c2536699aa1bec4c9 (patch) | |
tree | 1905d1bf6aa71844c1d555af6038301298c86492 /source/blender/blenlib/BLI_buffer.h | |
parent | 9190c493c17b09dc52b96bb46439d03df086ad7c (diff) |
add assert to BLI_buffer_at if a type is given different to 'elem_size'
Diffstat (limited to 'source/blender/blenlib/BLI_buffer.h')
-rw-r--r-- | source/blender/blenlib/BLI_buffer.h | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/source/blender/blenlib/BLI_buffer.h b/source/blender/blenlib/BLI_buffer.h index 4f053179d84..880a97acb80 100644 --- a/source/blender/blenlib/BLI_buffer.h +++ b/source/blender/blenlib/BLI_buffer.h @@ -72,13 +72,14 @@ enum { 0, \ flag_} -#define BLI_buffer_at(buffer_, type_, index_) \ - (((type_*)(buffer_)->data)[index_]) -#define BLI_buffer_append(buffer_, type_, val_) { \ - BLI_buffer_resize(buffer_, (buffer_)->count + 1); \ - BLI_buffer_at(buffer_, type_, (buffer_)->count - 1) = val_; \ -} (void)0 +#define BLI_buffer_at(buffer_, type_, index_) ( \ + (((type_ *)(buffer_)->data)[(BLI_assert(sizeof(type_) == (buffer_)->elem_size)), index_])) + +#define BLI_buffer_append(buffer_, type_, val_) ( \ + BLI_buffer_resize(buffer_, (buffer_)->count + 1), \ + (BLI_buffer_at(buffer_, type_, (buffer_)->count - 1) = val_) \ +) /* Never decreases the amount of memory allocated */ void BLI_buffer_resize(BLI_Buffer *buffer, int new_count); |