Fix *_appendv bug

This commit is contained in:
gingerBill 2016-05-03 23:56:20 +01:00
parent 1e62616e4e
commit e6a815749a
2 changed files with 6 additions and 5 deletions

View File

@ -4,7 +4,7 @@ gb single-file public domain libraries for C & C++
library | latest version | category | languages | description library | latest version | category | languages | description
----------------|----------------|----------|-----------|------------- ----------------|----------------|----------|-----------|-------------
**gb.h** | 0.08 | misc | C, C++ | A C helper library for C & C++ **gb.h** | 0.08a | misc | C, C++ | A C helper library for C & C++
**gb_math.h** | 0.06b | math | C, C++ | A C/C++ vector math library geared towards game development **gb_math.h** | 0.06b | math | C, C++ | A C/C++ vector math library geared towards game development
**gb_gl.h** | 0.04b | graphics | C, C++ | A C/C++ OpenGL Helper Library **gb_gl.h** | 0.04b | graphics | C, C++ | A C/C++ OpenGL Helper Library
**gb_string.h** | 0.95 | strings | C, C++ | A better string library for C & C++ (this is built into gb.h too with custom allocator support!) **gb_string.h** | 0.95 | strings | C, C++ | A better string library for C & C++ (this is built into gb.h too with custom allocator support!)

9
gb.h
View File

@ -1,4 +1,4 @@
/* gb.h - v0.08 - Ginger Bill's C Helper Library - public domain /* gb.h - v0.08a - Ginger Bill's C Helper Library - public domain
- no warranty implied; use at your own risk - no warranty implied; use at your own risk
This is a single header file with a bunch of useful stuff This is a single header file with a bunch of useful stuff
@ -26,6 +26,7 @@ Conventions used:
Version History: Version History:
0.08a - Fix *_appendv bug
0.08 - Huge Overhaul! 0.08 - Huge Overhaul!
0.07a - Fix alignment in gb_heap_allocator_proc 0.07a - Fix alignment in gb_heap_allocator_proc
0.07 - Hash Table and Hashing Functions 0.07 - Hash Table and Hashing Functions
@ -1142,10 +1143,10 @@ typedef struct gbBufferHeader {
#define gb_buffer_append(x, item) do { (x)[gb_buffer_count(x)++] = (item); } while (0) #define gb_buffer_append(x, item) do { (x)[gb_buffer_count(x)++] = (item); } while (0)
#define gb_buffer_appednv(x, items, item_count) do { \ #define gb_buffer_appendv(x, items, item_count) do { \
GB_ASSERT(gb_size_of(*(items)) == gb_size_of(*(x))); \ GB_ASSERT(gb_size_of(*(items)) == gb_size_of(*(x))); \
GB_ASSERT(gb_buffer_count(x)+item_count <= gb_buffer_capacity(x)); \ GB_ASSERT(gb_buffer_count(x)+item_count <= gb_buffer_capacity(x)); \
gb_memcopy((x)[gb_buffer_count(x)], (items), gb_size_of(*(x))*(item_count)); \ gb_memcopy(&(x)[gb_buffer_count(x)], (items), gb_size_of(*(x))*(item_count)); \
gb_buffer_count(x) += (item_count); \ gb_buffer_count(x) += (item_count); \
} while (0) } while (0)
@ -1286,7 +1287,7 @@ GB_DEF void *gb__set_array_capacity(void *array, isize capacity, isize element_s
GB_ASSERT(gb_size_of((items)[0]) == gb_size_of((x)[0])); \ GB_ASSERT(gb_size_of((items)[0]) == gb_size_of((x)[0])); \
if (gb__ah->capacity < gb__ah->count+(item_count)) \ if (gb__ah->capacity < gb__ah->count+(item_count)) \
gb_array_grow(x, gb__ah->count+(item_count)); \ gb_array_grow(x, gb__ah->count+(item_count)); \
gb_memcopy((x)[gb__ah->count], (items), gb_size_of((x)[0])*(item_count));\ gb_memcopy(&(x)[gb__ah->count], (items), gb_size_of((x)[0])*(item_count));\
gb__ah->count += (item_count); \ gb__ah->count += (item_count); \
} while (0) } while (0)