mirror of https://github.com/mgba-emu/mgba.git
All: Use calloc instead of malloc in several places
This commit is contained in:
parent
2f066a9790
commit
029b0b937a
|
@ -41,7 +41,7 @@ CXX_GUARD_START
|
|||
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); \
|
||||
|
|
|
@ -42,7 +42,7 @@ static void _redoCacheSize(struct mBitmapCache* cache) {
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ static struct mInputMapImpl* _guaranteeMap(struct mInputMap* map, uint32_t type)
|
|||
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 @@ static struct mInputMapImpl* _guaranteeMap(struct mInputMap* map, uint32_t type)
|
|||
}
|
||||
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 @@ static struct mInputMapImpl* _guaranteeMap(struct mInputMap* map, uint32_t type)
|
|||
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;
|
||||
|
|
|
@ -46,8 +46,8 @@ static void _redoCacheSize(struct mTileCache* cache) {
|
|||
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) {
|
||||
|
|
|
@ -174,7 +174,7 @@ static bool _parseExpression(struct mDebugger* debugger, struct CLIDebugVector*
|
|||
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;
|
||||
|
|
|
@ -31,7 +31,7 @@ struct GUIFont* GUIFontCreate(void) {
|
|||
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) {
|
||||
|
|
|
@ -921,7 +921,7 @@ bool mGLES2ShaderLoad(struct VideoShader* shader, struct VDir* dir) {
|
|||
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 @@ bool mGLES2ShaderLoad(struct VideoShader* shader, struct VDir* dir) {
|
|||
}
|
||||
}
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue