Mercurial > hg > dmlib
comparison tools/lib64gfx.c @ 1851:cfc7046fb176
Reallocate buffer only if the new size is larger in dmC64MemBlockReAlloc().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 22 Jun 2018 23:11:58 +0300 |
parents | 88cef7758303 |
children | 219417325036 |
comparison
equal
deleted
inserted
replaced
1850:3d6917948061 | 1851:cfc7046fb176 |
---|---|
174 } | 174 } |
175 | 175 |
176 | 176 |
177 int dmC64MemBlockReAlloc(DMC64MemBlock *blk, const size_t size) | 177 int dmC64MemBlockReAlloc(DMC64MemBlock *blk, const size_t size) |
178 { | 178 { |
179 // Reallocate only if new size is larger | |
180 if (size <= blk->size) | |
181 return DMERR_OK; | |
182 | |
179 if ((blk->data = dmRealloc(blk->data, size)) == NULL) | 183 if ((blk->data = dmRealloc(blk->data, size)) == NULL) |
180 return DMERR_MALLOC; | 184 return DMERR_MALLOC; |
181 | 185 |
182 dmMemset(blk->data + blk->size, 0, size - blk->size); | 186 dmMemset(blk->data + blk->size, 0, size - blk->size); |
187 | |
183 blk->size = size; | 188 blk->size = size; |
184 return DMERR_OK; | 189 return DMERR_OK; |
185 } | 190 } |
186 | 191 |
187 | 192 |