diff --git a/source/blender/nodes/composite/nodes/node_composite_convert_color_space.cc b/source/blender/nodes/composite/nodes/node_composite_convert_color_space.cc index 8e8d3767465..25191233979 100644 --- a/source/blender/nodes/composite/nodes/node_composite_convert_color_space.cc +++ b/source/blender/nodes/composite/nodes/node_composite_convert_color_space.cc @@ -35,8 +35,7 @@ static void CMP_NODE_CONVERT_COLOR_SPACE_declare(NodeDeclarationBuilder &b) static void node_composit_init_convert_colorspace(bNodeTree * /*ntree*/, bNode *node) { - NodeConvertColorSpace *ncs = static_cast( - MEM_callocN(sizeof(NodeConvertColorSpace), "node colorspace")); + NodeConvertColorSpace *ncs = MEM_callocN("node colorspace"); const char *first_colorspace = IMB_colormanagement_role_colorspace_name_get( COLOR_ROLE_SCENE_LINEAR); if (first_colorspace && first_colorspace[0]) { diff --git a/source/blender/nodes/composite/nodes/node_composite_file_output.cc b/source/blender/nodes/composite/nodes/node_composite_file_output.cc index d99ccbf6a36..c62625f4f49 100644 --- a/source/blender/nodes/composite/nodes/node_composite_file_output.cc +++ b/source/blender/nodes/composite/nodes/node_composite_file_output.cc @@ -710,8 +710,8 @@ class FileOutputOperation : public NodeOperation { switch (result.type()) { case ResultType::Float: { - float *buffer = static_cast(MEM_malloc_arrayN( - size_t(size.x) * size.y, sizeof(float), "File Output Inflated Buffer.")); + float *buffer = MEM_malloc_arrayN(size_t(size.x) * size_t(size.y), + "File Output Inflated Buffer."); const float value = result.get_single_value(); parallel_for( @@ -719,8 +719,8 @@ class FileOutputOperation : public NodeOperation { return buffer; } case ResultType::Color: { - float *buffer = static_cast(MEM_malloc_arrayN( - size_t(size.x) * size.y, sizeof(float[4]), "File Output Inflated Buffer.")); + float *buffer = MEM_malloc_arrayN(4 * size_t(size.x) * size_t(size.y), + "File Output Inflated Buffer."); const float4 value = result.get_single_value(); parallel_for(size, [&](const int2 texel) { @@ -729,8 +729,8 @@ class FileOutputOperation : public NodeOperation { return buffer; } case ResultType::Float4: { - float *buffer = static_cast(MEM_malloc_arrayN( - size_t(size.x) * size.y, sizeof(float[4]), "File Output Inflated Buffer.")); + float *buffer = MEM_malloc_arrayN(4 * size_t(size.x) * size_t(size.y), + "File Output Inflated Buffer."); const float4 value = result.get_single_value(); parallel_for(size, [&](const int2 texel) { @@ -739,8 +739,8 @@ class FileOutputOperation : public NodeOperation { return buffer; } case ResultType::Float3: { - float *buffer = static_cast(MEM_malloc_arrayN( - size_t(size.x) * size.y, sizeof(float[3]), "File Output Inflated Buffer.")); + float *buffer = MEM_malloc_arrayN(3 * size_t(size.x) * size_t(size.y), + "File Output Inflated Buffer."); const float3 value = result.get_single_value(); parallel_for(size, [&](const int2 texel) { @@ -808,8 +808,8 @@ class FileOutputOperation : public NodeOperation { * input image is freed. */ float *float4_to_float3_image(int2 size, float *float4_image) { - float *float3_image = static_cast(MEM_malloc_arrayN( - size_t(size.x) * size.y, sizeof(float[3]), "File Output Vector Buffer.")); + float *float3_image = MEM_malloc_arrayN(3 * size_t(size.x) * size_t(size.y), + "File Output Vector Buffer."); parallel_for(size, [&](const int2 texel) { for (int i = 0; i < 3; i++) { diff --git a/source/blender/nodes/composite/nodes/node_composite_image.cc b/source/blender/nodes/composite/nodes/node_composite_image.cc index 55adfd5e5af..99ae0ba31b6 100644 --- a/source/blender/nodes/composite/nodes/node_composite_image.cc +++ b/source/blender/nodes/composite/nodes/node_composite_image.cc @@ -310,8 +310,7 @@ static void cmp_node_rlayer_create_outputs(bNodeTree *ntree, if (engine_type && engine_type->update_render_passes) { ViewLayer *view_layer = (ViewLayer *)BLI_findlink(&scene->view_layers, node->custom1); if (view_layer) { - RLayerUpdateData *data = (RLayerUpdateData *)MEM_mallocN(sizeof(RLayerUpdateData), - "render layer update data"); + RLayerUpdateData *data = MEM_mallocN("render layer update data"); data->available_sockets = available_sockets; data->prev_index = -1; node->storage = data; diff --git a/source/blender/nodes/function/nodes/node_fn_input_string.cc b/source/blender/nodes/function/nodes/node_fn_input_string.cc index 8e7c232aa31..7213bb09e0b 100644 --- a/source/blender/nodes/function/nodes/node_fn_input_string.cc +++ b/source/blender/nodes/function/nodes/node_fn_input_string.cc @@ -30,7 +30,7 @@ static void node_build_multi_function(NodeMultiFunctionBuilder &builder) static void node_init(bNodeTree * /*tree*/, bNode *node) { - node->storage = MEM_callocN(sizeof(NodeInputString), __func__); + node->storage = MEM_callocN(__func__); } static void node_storage_free(bNode *node) diff --git a/source/blender/nodes/geometry/nodes/node_geo_boolean.cc b/source/blender/nodes/geometry/nodes/node_geo_boolean.cc index cb70e741ec7..039371099ce 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_boolean.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_boolean.cc @@ -198,8 +198,7 @@ static void node_geo_exec(GeoNodeExecParams params) } MEM_SAFE_FREE(result->mat); - result->mat = static_cast( - MEM_malloc_arrayN(materials.size(), sizeof(Material *), __func__)); + result->mat = MEM_malloc_arrayN(size_t(materials.size()), __func__); result->totcol = materials.size(); MutableSpan(result->mat, result->totcol).copy_from(materials); diff --git a/source/blender/nodes/geometry/nodes/node_geo_string_to_curves.cc b/source/blender/nodes/geometry/nodes/node_geo_string_to_curves.cc index 0173c576298..c35bdb0da68 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_string_to_curves.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_string_to_curves.cc @@ -185,7 +185,7 @@ static std::optional get_text_layout(GeoNodeExecParams ¶ms) cu.linedist = line_spacing; cu.vfont = vfont; cu.overflow = overflow; - cu.tb = static_cast(MEM_calloc_arrayN(MAXTEXTBOX, sizeof(TextBox), __func__)); + cu.tb = MEM_calloc_arrayN(MAXTEXTBOX, __func__); cu.tb->w = textbox_w; cu.tb->h = textbox_h; cu.totbox = 1; @@ -197,7 +197,7 @@ static std::optional get_text_layout(GeoNodeExecParams ¶ms) /* The reason for the additional character here is unknown, but reflects other code elsewhere. */ cu.str = static_cast(MEM_mallocN(len_bytes + sizeof(char32_t), __func__)); memcpy(cu.str, layout.text.c_str(), len_bytes + 1); - cu.strinfo = static_cast(MEM_callocN((len_chars + 1) * sizeof(CharInfo), __func__)); + cu.strinfo = MEM_calloc_arrayN(len_chars + 1, __func__); CharTrans *chartransdata = nullptr; int text_len; diff --git a/source/blender/nodes/intern/geometry_nodes_execute.cc b/source/blender/nodes/intern/geometry_nodes_execute.cc index 75339632cb6..8f730f714ec 100644 --- a/source/blender/nodes/intern/geometry_nodes_execute.cc +++ b/source/blender/nodes/intern/geometry_nodes_execute.cc @@ -145,7 +145,7 @@ std::unique_ptr id_property_create_f ui_data->base.rna_subtype = value->subtype; ui_data->soft_min = double(value->min); ui_data->soft_max = double(value->max); - ui_data->default_array = (double *)MEM_mallocN(sizeof(double[3]), "mod_prop_default"); + ui_data->default_array = MEM_malloc_arrayN(3, "mod_prop_default"); ui_data->default_array_len = 3; for (const int i : IndexRange(3)) { ui_data->default_array[i] = double(value->value[i]); @@ -160,7 +160,7 @@ std::unique_ptr id_property_create_f Span{value->value[0], value->value[1], value->value[2], value->value[3]}); IDPropertyUIDataFloat *ui_data = (IDPropertyUIDataFloat *)IDP_ui_data_ensure(property.get()); ui_data->base.rna_subtype = PROP_COLOR; - ui_data->default_array = (double *)MEM_mallocN(sizeof(double[4]), __func__); + ui_data->default_array = MEM_malloc_arrayN(4, __func__); ui_data->default_array_len = 4; ui_data->min = 0.0; ui_data->max = FLT_MAX; diff --git a/source/blender/nodes/intern/node_exec.cc b/source/blender/nodes/intern/node_exec.cc index 2197bb3de2a..b623bc47fe3 100644 --- a/source/blender/nodes/intern/node_exec.cc +++ b/source/blender/nodes/intern/node_exec.cc @@ -187,11 +187,10 @@ bNodeTreeExec *ntree_exec_begin(bNodeExecContext *context, /* allocated exec data pointers for nodes */ exec->totnodes = nodelist.size(); - exec->nodeexec = (bNodeExec *)MEM_callocN(exec->totnodes * sizeof(bNodeExec), - "node execution data"); + exec->nodeexec = MEM_calloc_arrayN(size_t(exec->totnodes), "node execution data"); /* allocate data pointer for node stack */ exec->stacksize = index; - exec->stack = (bNodeStack *)MEM_callocN(exec->stacksize * sizeof(bNodeStack), "bNodeStack"); + exec->stack = MEM_calloc_arrayN(size_t(exec->stacksize), "bNodeStack"); /* all non-const results are considered inputs */ int n; diff --git a/source/blender/nodes/shader/node_shader_tree.cc b/source/blender/nodes/shader/node_shader_tree.cc index ab5166ccd82..dbdc1777f33 100644 --- a/source/blender/nodes/shader/node_shader_tree.cc +++ b/source/blender/nodes/shader/node_shader_tree.cc @@ -1282,8 +1282,7 @@ bNodeTreeExec *ntreeShaderBeginExecTree_internal(bNodeExecContext *context, bNodeTreeExec *exec = ntree_exec_begin(context, ntree, parent_key); /* allocate the thread stack listbase array */ - exec->threadstack = static_cast( - MEM_callocN(BLENDER_MAX_THREADS * sizeof(ListBase), "thread stack array")); + exec->threadstack = MEM_calloc_arrayN(BLENDER_MAX_THREADS, "thread stack array"); LISTBASE_FOREACH (bNode *, node, &exec->nodetree->nodes) { node->runtime->need_exec = 1; diff --git a/source/blender/nodes/shader/nodes/node_shader_blackbody.cc b/source/blender/nodes/shader/nodes/node_shader_blackbody.cc index 2587baa2abd..8ddf263f50e 100644 --- a/source/blender/nodes/shader/nodes/node_shader_blackbody.cc +++ b/source/blender/nodes/shader/nodes/node_shader_blackbody.cc @@ -29,7 +29,7 @@ static int node_shader_gpu_blackbody(GPUMaterial *mat, GPUNodeStack *out) { const int size = CM_TABLE + 1; - float *data = static_cast(MEM_mallocN(sizeof(float) * size * 4, "blackbody texture")); + float *data = MEM_malloc_arrayN(size * 4, "blackbody texture"); IMB_colormanagement_blackbody_temperature_to_rgb_table(data, size, 800.0f, 12000.0f); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.cc b/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.cc index 8d00c56f396..481d72269e6 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.cc @@ -73,8 +73,7 @@ static void node_shader_buts_tex_pointdensity(uiLayout *layout, bContext * /*C*/ static void node_shader_init_tex_pointdensity(bNodeTree * /*ntree*/, bNode *node) { - NodeShaderTexPointDensity *point_density = static_cast( - MEM_callocN(sizeof(NodeShaderTexPointDensity), __func__)); + NodeShaderTexPointDensity *point_density = MEM_callocN(__func__); point_density->resolution = 100; point_density->radius = 0.3f; point_density->space = SHD_POINTDENSITY_SPACE_OBJECT; diff --git a/source/blender/nodes/shader/nodes/node_shader_volume_principled.cc b/source/blender/nodes/shader/nodes/node_shader_volume_principled.cc index 95fd81a8d6d..ca08d33102e 100644 --- a/source/blender/nodes/shader/nodes/node_shader_volume_principled.cc +++ b/source/blender/nodes/shader/nodes/node_shader_volume_principled.cc @@ -124,11 +124,11 @@ static int node_shader_gpu_volume_principled(GPUMaterial *mat, const int size = CM_TABLE + 1; float *data, layer; if (use_blackbody) { - data = (float *)MEM_mallocN(sizeof(float) * size * 4, "blackbody texture"); + data = MEM_malloc_arrayN(size * 4, "blackbody texture"); IMB_colormanagement_blackbody_temperature_to_rgb_table(data, size, 800.0f, 12000.0f); } else { - data = (float *)MEM_callocN(sizeof(float) * size * 4, "blackbody black"); + data = MEM_calloc_arrayN(size * 4, "blackbody black"); } GPUNodeLink *spectrummap = GPU_color_band(mat, size, data, &layer); diff --git a/source/blender/nodes/shader/nodes/node_shader_wavelength.cc b/source/blender/nodes/shader/nodes/node_shader_wavelength.cc index 8c765646e07..a4a35e83cc8 100644 --- a/source/blender/nodes/shader/nodes/node_shader_wavelength.cc +++ b/source/blender/nodes/shader/nodes/node_shader_wavelength.cc @@ -25,7 +25,7 @@ static int node_shader_gpu_wavelength(GPUMaterial *mat, GPUNodeStack *out) { const int size = CM_TABLE + 1; - float *data = static_cast(MEM_mallocN(sizeof(float) * size * 4, "cie_xyz texture")); + float *data = MEM_malloc_arrayN(size * 4, "cie_xyz texture"); IMB_colormanagement_wavelength_to_rgb_table(data, size); diff --git a/source/blender/nodes/texture/nodes/node_texture_proc.cc b/source/blender/nodes/texture/nodes/node_texture_proc.cc index 3687018a04f..92283c71517 100644 --- a/source/blender/nodes/texture/nodes/node_texture_proc.cc +++ b/source/blender/nodes/texture/nodes/node_texture_proc.cc @@ -240,7 +240,7 @@ ProcDef(stucci); static void init(bNodeTree * /*ntree*/, bNode *node) { - Tex *tex = static_cast(MEM_callocN(sizeof(Tex), "Tex")); + Tex *tex = MEM_callocN("Tex"); node->storage = tex; BKE_texture_default(tex);