all repos — mgba @ 029b0b937a098f1a202e0c3dfc626458b66dcb43

mGBA Game Boy Advance Emulator

All: Use calloc instead of malloc in several places
Vicki Pfau vi@endrift.com
Tue, 07 Jul 2020 18:02:34 -0700
commit

029b0b937a098f1a202e0c3dfc626458b66dcb43

parent

2f066a979031136e7686ceee91af9e8a2e7cc754

M include/mgba-util/vector.hinclude/mgba-util/vector.h

@@ -41,7 +41,7 @@ if (capacity == 0) { \

capacity = 4; \ } \ vector->capacity = capacity; \ - vector->vector = malloc(sizeof(TYPE) * capacity); \ + vector->vector = calloc(capacity, sizeof(TYPE)); \ } \ void NAME ## Deinit(struct NAME* vector) { \ free(vector->vector); \
M src/core/bitmap-cache.csrc/core/bitmap-cache.c

@@ -42,7 +42,7 @@ size_t size = mBitmapCacheSystemInfoGetHeight(cache->sysConfig) * mBitmapCacheSystemInfoGetBuffers(cache->sysConfig);

cache->cache = anonymousMemoryMap(mBitmapCacheSystemInfoGetWidth(cache->sysConfig) * size * sizeof(color_t)); cache->status = anonymousMemoryMap(size * sizeof(*cache->status)); if (mBitmapCacheSystemInfoIsUsesPalette(cache->sysConfig)) { - cache->palette = malloc((1 << (1 << mBitmapCacheSystemInfoGetEntryBPP(cache->sysConfig))) * sizeof(color_t)); + cache->palette = calloc((1 << (1 << mBitmapCacheSystemInfoGetEntryBPP(cache->sysConfig))), sizeof(color_t)); } else { cache->palette = NULL; }
M src/core/input.csrc/core/input.c

@@ -88,7 +88,7 @@ map->maps = malloc(sizeof(*map->maps));

map->numMaps = 1; impl = &map->maps[0]; impl->type = type; - impl->map = malloc(map->info->nKeys * sizeof(int)); + impl->map = calloc(map->info->nKeys, sizeof(int)); size_t i; for (i = 0; i < map->info->nKeys; ++i) { impl->map[i] = -1;

@@ -108,7 +108,7 @@ }

} if (impl) { impl->type = type; - impl->map = malloc(map->info->nKeys * sizeof(int)); + impl->map = calloc(map->info->nKeys, sizeof(int)); size_t i; for (i = 0; i < map->info->nKeys; ++i) { impl->map[i] = -1;

@@ -122,7 +122,7 @@ }

map->numMaps *= 2; impl = &map->maps[m]; impl->type = type; - impl->map = malloc(map->info->nKeys * sizeof(int)); + impl->map = calloc(map->info->nKeys, sizeof(int)); size_t i; for (i = 0; i < map->info->nKeys; ++i) { impl->map[i] = -1;
M src/core/tile-cache.csrc/core/tile-cache.c

@@ -46,8 +46,8 @@ cache->entriesPerTile = size;

unsigned tiles = mTileCacheSystemInfoGetMaxTiles(cache->sysConfig); cache->cache = anonymousMemoryMap(8 * 8 * sizeof(color_t) * tiles * size); cache->status = anonymousMemoryMap(tiles * size * sizeof(*cache->status)); - cache->globalPaletteVersion = malloc(size * sizeof(*cache->globalPaletteVersion)); - cache->palette = malloc(size * bpp * sizeof(*cache->palette)); + cache->globalPaletteVersion = calloc(size, sizeof(*cache->globalPaletteVersion)); + cache->palette = calloc(size * bpp, sizeof(*cache->palette)); } void mTileCacheConfigure(struct mTileCache* cache, mTileCacheConfiguration config) {
M src/debugger/cli-debugger.csrc/debugger/cli-debugger.c

@@ -174,7 +174,7 @@ struct CLIDebugVector* accum;

for (accum = dv; accum; accum = accum->next) { ++args; } - const char** arglist = malloc(sizeof(const char*) * (args + 1)); + const char** arglist = calloc(args + 1, sizeof(const char*)); args = 0; for (accum = dv; accum; accum = accum->next) { arglist[args] = accum->charValue;
M src/platform/3ds/gui-font.csrc/platform/3ds/gui-font.c

@@ -31,7 +31,7 @@

guiFont->font = fontGetSystemFont(); TGLP_s* glyphInfo = fontGetGlyphInfo(guiFont->font); guiFont->size = FONT_SIZE / glyphInfo->cellHeight; - guiFont->sheets = malloc(sizeof(*guiFont->sheets) * glyphInfo->nSheets); + guiFont->sheets = calloc(glyphInfo->nSheets, sizeof(*guiFont->sheets)); int i; for (i = 0; i < glyphInfo->nSheets; ++i) {
M src/platform/opengl/gles2.csrc/platform/opengl/gles2.c

@@ -921,7 +921,7 @@ if (inShaders > MAX_PASSES || inShaders < 1) {

success = false; } if (success) { - struct mGLES2Shader* shaderBlock = malloc(sizeof(struct mGLES2Shader) * inShaders); + struct mGLES2Shader* shaderBlock = calloc(inShaders, sizeof(struct mGLES2Shader)); int n; for (n = 0; n < inShaders; ++n) { char passName[12];

@@ -980,7 +980,7 @@ --u;

} } u = mGLES2UniformListSize(&uniformVector); - struct mGLES2Uniform* uniformBlock = malloc(sizeof(*uniformBlock) * u); + struct mGLES2Uniform* uniformBlock = calloc(u, sizeof(*uniformBlock)); memcpy(uniformBlock, mGLES2UniformListGetPointer(&uniformVector, 0), sizeof(*uniformBlock) * u); mGLES2UniformListDeinit(&uniformVector);