Cleanup: replace MEM_callocN with MEM_mallocN when overwritten afterward

Also pair allocation with memcpy calls.
This commit is contained in:
Campbell Barton 2023-08-05 20:06:42 +10:00
parent 9150f6d1a9
commit b879a4f2d8
6 changed files with 9 additions and 9 deletions

View File

@ -40,7 +40,7 @@ bUserAssetLibrary *BKE_preferences_asset_library_add(UserDef *userdef,
const char *dirpath)
{
bUserAssetLibrary *library = static_cast<bUserAssetLibrary *>(
MEM_callocN(sizeof(*library), "bUserAssetLibrary"));
MEM_mallocN(sizeof(*library), "bUserAssetLibrary"));
memcpy(library, DNA_struct_default_get(bUserAssetLibrary), sizeof(*library));
BLI_addtail(&userdef->asset_libraries, library);

View File

@ -32,10 +32,10 @@ static void flatten_string_append(FlattenString *fs, const char *c, int accum, i
fs->len *= 2;
nbuf = static_cast<char *>(MEM_callocN(sizeof(*fs->buf) * fs->len, "fs->buf"));
naccum = static_cast<int *>(MEM_callocN(sizeof(*fs->accum) * fs->len, "fs->accum"));
memcpy(nbuf, fs->buf, sizeof(*fs->buf) * fs->pos);
memcpy(nbuf, fs->buf, fs->pos * sizeof(*fs->buf));
memcpy(naccum, fs->accum, fs->pos * sizeof(*fs->accum));
naccum = static_cast<int *>(MEM_callocN(sizeof(*fs->accum) * fs->len, "fs->accum"));
memcpy(naccum, fs->accum, sizeof(*fs->accum) * fs->pos);
if (fs->buf != fs->fixedbuf) {
MEM_freeN(fs->buf);

View File

@ -174,7 +174,7 @@ static bool stroke_dash(const bGPDstroke *gps,
for (int di = 0; di < stroke->totpoints; di++) {
MDeformVert *dv = &gps->dvert[new_stroke_offset + di];
if (dv && dv->totweight && dv->dw) {
MDeformWeight *dw = (MDeformWeight *)MEM_callocN(sizeof(MDeformWeight) * dv->totweight,
MDeformWeight *dw = (MDeformWeight *)MEM_mallocN(sizeof(MDeformWeight) * dv->totweight,
__func__);
memcpy(dw, dv->dw, sizeof(MDeformWeight) * dv->totweight);
stroke->dvert[di].dw = dw;

View File

@ -1160,7 +1160,7 @@ bool lineart_main_try_generate_shadow(Depsgraph *depsgraph,
}
LineartData *ld = static_cast<LineartData *>(
MEM_callocN(sizeof(LineartData), "LineArt render buffer copied"));
MEM_mallocN(sizeof(LineartData), "LineArt render buffer copied"));
memcpy(ld, original_ld, sizeof(LineartData));
BLI_spin_init(&ld->lock_task);

View File

@ -594,10 +594,10 @@ static void rna_Curve_body_set(PointerRNA *ptr, const char *value)
}
cu->str = static_cast<char *>(MEM_mallocN(len_bytes + sizeof(char32_t), "str"));
memcpy(cu->str, value, len_bytes + 1);
cu->strinfo = static_cast<CharInfo *>(
MEM_callocN((len_chars + 4) * sizeof(CharInfo), "strinfo"));
memcpy(cu->str, value, len_bytes + 1);
}
static void rna_Nurb_update_cyclic_u(Main *bmain, Scene *scene, PointerRNA *ptr)

View File

@ -209,8 +209,8 @@ static std::optional<TextLayout> get_text_layout(GeoNodeExecParams &params)
cu.pos = len_chars;
/* The reason for the additional character here is unknown, but reflects other code elsewhere. */
cu.str = static_cast<char *>(MEM_mallocN(len_bytes + sizeof(char32_t), __func__));
cu.strinfo = static_cast<CharInfo *>(MEM_callocN((len_chars + 1) * sizeof(CharInfo), __func__));
memcpy(cu.str, layout.text.c_str(), len_bytes + 1);
cu.strinfo = static_cast<CharInfo *>(MEM_callocN((len_chars + 1) * sizeof(CharInfo), __func__));
CharTrans *chartransdata = nullptr;
int text_len;