diff --git a/intern/ghost/intern/GHOST_C-api.cc b/intern/ghost/intern/GHOST_C-api.cc index 3596fde3101..45e14347118 100644 --- a/intern/ghost/intern/GHOST_C-api.cc +++ b/intern/ghost/intern/GHOST_C-api.cc @@ -584,13 +584,14 @@ char *GHOST_GetTitle(GHOST_WindowHandle windowhandle) GHOST_IWindow *window = (GHOST_IWindow *)windowhandle; std::string title = window->getTitle(); - char *ctitle = (char *)malloc(title.size() + 1); + const size_t ctitle_size = title.size() + 1; + char *ctitle = (char *)malloc(ctitle_size); if (ctitle == nullptr) { return nullptr; } - strcpy(ctitle, title.c_str()); + memcpy(ctitle, title.c_str(), ctitle_size); return ctitle; } diff --git a/intern/ghost/intern/GHOST_SystemX11.cc b/intern/ghost/intern/GHOST_SystemX11.cc index 662ee8ba0d7..48862b3d2d7 100644 --- a/intern/ghost/intern/GHOST_SystemX11.cc +++ b/intern/ghost/intern/GHOST_SystemX11.cc @@ -2190,12 +2190,14 @@ char *GHOST_SystemX11::getClipboard(bool selection) const owner = XGetSelectionOwner(m_display, sseln); if (owner == win) { if (sseln == m_atom.CLIPBOARD) { - sel_buf = (char *)malloc(strlen(txt_cut_buffer) + 1); - strcpy(sel_buf, txt_cut_buffer); + size_t sel_buf_size = strlen(txt_cut_buffer) + 1; + sel_buf = (char *)malloc(sel_buf_size); + memcpy(sel_buf, txt_cut_buffer, sel_buf_size); return sel_buf; } - sel_buf = (char *)malloc(strlen(txt_select_buffer) + 1); - strcpy(sel_buf, txt_select_buffer); + size_t sel_buf_size = strlen(txt_select_buffer) + 1; + sel_buf = (char *)malloc(sel_buf_size); + memcpy(sel_buf, txt_select_buffer, sel_buf_size); return sel_buf; } if (owner == None) { @@ -2289,8 +2291,9 @@ void GHOST_SystemX11::putClipboard(const char *buffer, bool selection) const free((void *)txt_cut_buffer); } - txt_cut_buffer = (char *)malloc(strlen(buffer) + 1); - strcpy(txt_cut_buffer, buffer); + size_t buffer_size = strlen(buffer) + 1; + txt_cut_buffer = (char *)malloc(buffer_size); + memcpy(txt_cut_buffer, buffer, buffer_size); } else { XSetSelectionOwner(m_display, m_atom.PRIMARY, m_window, CurrentTime); @@ -2299,8 +2302,9 @@ void GHOST_SystemX11::putClipboard(const char *buffer, bool selection) const free((void *)txt_select_buffer); } - txt_select_buffer = (char *)malloc(strlen(buffer) + 1); - strcpy(txt_select_buffer, buffer); + size_t buffer_size = strlen(buffer) + 1; + txt_select_buffer = (char *)malloc(buffer_size); + memcpy(txt_select_buffer, buffer, buffer_size); } if (owner != m_window) { diff --git a/source/blender/blenkernel/intern/armature_test.cc b/source/blender/blenkernel/intern/armature_test.cc index b58878d9bb0..179569847d4 100644 --- a/source/blender/blenkernel/intern/armature_test.cc +++ b/source/blender/blenkernel/intern/armature_test.cc @@ -355,9 +355,9 @@ class BKE_armature_find_selected_bones_test : public testing::Test { void SetUp() override { - strcpy(bone1.name, "bone1"); - strcpy(bone2.name, "bone2"); - strcpy(bone3.name, "bone3"); + STRNCPY(bone1.name, "bone1"); + STRNCPY(bone2.name, "bone2"); + STRNCPY(bone3.name, "bone3"); arm.bonebase = {nullptr, nullptr}; bone1.childbase = {nullptr, nullptr}; diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index 29c4d2c0cd3..53428568ae9 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -147,7 +147,7 @@ void BKE_blender_globals_init(void) BKE_blender_globals_main_replace(BKE_main_new()); - strcpy(G.ima, "//"); + STRNCPY(G.ima, "//"); #ifndef WITH_PYTHON_SECURITY /* default */ G.f |= G_FLAG_SCRIPT_AUTOEXEC; diff --git a/source/blender/blenkernel/intern/boids.c b/source/blender/blenkernel/intern/boids.c index c51b1ae642b..67b4e8f7406 100644 --- a/source/blender/blenkernel/intern/boids.c +++ b/source/blender/blenkernel/intern/boids.c @@ -1657,7 +1657,7 @@ BoidState *boid_new_state(BoidSettings *boids) SNPRINTF(state->name, "State %i", state->id); } else { - strcpy(state->name, "State"); + STRNCPY(state->name, "State"); } state->rule_fuzziness = 0.5; diff --git a/source/blender/blenkernel/intern/freestyle.c b/source/blender/blenkernel/intern/freestyle.c index 19d0f0ed8eb..46c3c820da7 100644 --- a/source/blender/blenkernel/intern/freestyle.c +++ b/source/blender/blenkernel/intern/freestyle.c @@ -99,7 +99,7 @@ static void copy_lineset(FreestyleLineSet *new_lineset, FreestyleLineSet *linese new_lineset->edge_types = lineset->edge_types; new_lineset->exclude_edge_types = lineset->exclude_edge_types; new_lineset->group = lineset->group; - strcpy(new_lineset->name, lineset->name); + STRNCPY(new_lineset->name, lineset->name); if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) { id_us_plus((ID *)new_lineset->linestyle); @@ -187,7 +187,7 @@ FreestyleLineSet *BKE_freestyle_lineset_add(struct Main *bmain, SNPRINTF(lineset->name, "LineSet %i", lineset_index + 1); } else { - strcpy(lineset->name, "LineSet"); + STRNCPY(lineset->name, "LineSet"); } BKE_freestyle_lineset_unique_name(config, lineset); diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index 575d016b547..248fc125f6e 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -791,7 +791,7 @@ IDProperty *IDP_GetProperties(ID *id, const bool create_if_needed) /* NOTE(@ideasman42): Don't overwrite the data's name and type * some functions might need this if they * don't have a real ID, should be named elsewhere. */ - // strcpy(id->name, "top_level_group"); + // STRNCPY(id->name, "top_level_group"); } return id->properties; } diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c index 69ca10d21b7..1e656d8b195 100644 --- a/source/blender/blenkernel/intern/ipo.c +++ b/source/blender/blenkernel/intern/ipo.c @@ -1165,7 +1165,7 @@ static char *get_rna_access(ID *id, else if ((blocktype == ID_KE) && STREQ(actname, "Shape")) { /* Actionified "Shape" IPO's - * these are forced onto object level via the action container there... */ - strcpy(buf, "data.shape_keys"); + STRNCPY(buf, "data.shape_keys"); } else { /* Pose-Channel */ diff --git a/source/blender/blenkernel/intern/lattice_deform_test.cc b/source/blender/blenkernel/intern/lattice_deform_test.cc index 0ab23ea4bbe..4a3ef72019a 100644 --- a/source/blender/blenkernel/intern/lattice_deform_test.cc +++ b/source/blender/blenkernel/intern/lattice_deform_test.cc @@ -40,7 +40,7 @@ static void test_lattice_deform_init(LatticeDeformTestContext *ctx, ctx->coords[index][2] = (rng->get_float() - 0.5f) * 10; } IDType_ID_LT.init_data(&ctx->lattice.id); - strcpy(ctx->lattice.id.name, "LTLattice"); + STRNCPY(ctx->lattice.id.name, "LTLattice"); IDType_ID_OB.init_data(&ctx->ob_lattice.id); ctx->ob_lattice.type = OB_LATTICE; ctx->ob_lattice.data = &ctx->lattice; diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c index 2c8120dc5d9..a6667942a88 100644 --- a/source/blender/blenkernel/intern/lib_id.c +++ b/source/blender/blenkernel/intern/lib_id.c @@ -1620,7 +1620,7 @@ bool BKE_id_new_name_validate( result = BKE_main_namemap_get_name(bmain, id, name); - strcpy(id->name + 2, name); + BLI_strncpy(id->name + 2, name, sizeof(id->name) - 2); id_sort_by_name(lb, id, NULL); return result; } @@ -2012,7 +2012,7 @@ void BKE_libblock_rename(Main *bmain, ID *id, const char *name) void BKE_id_full_name_get(char name[MAX_ID_FULL_NAME], const ID *id, char separator_char) { - strcpy(name, id->name + 2); + BLI_strncpy(name, id->name + 2, MAX_ID_FULL_NAME); if (ID_IS_LINKED(id)) { const size_t idname_len = strlen(id->name + 2); @@ -2020,7 +2020,7 @@ void BKE_id_full_name_get(char name[MAX_ID_FULL_NAME], const ID *id, char separa name[idname_len] = separator_char ? separator_char : ' '; name[idname_len + 1] = '['; - strcpy(name + idname_len + 2, id->lib->id.name + 2); + BLI_strncpy(name + idname_len + 2, id->lib->id.name + 2, MAX_ID_FULL_NAME - (idname_len + 2)); name[idname_len + 2 + libname_len] = ']'; name[idname_len + 2 + libname_len + 1] = '\0'; } diff --git a/source/blender/blenkernel/intern/mask.cc b/source/blender/blenkernel/intern/mask.cc index 628cee94d1e..fb6b5954df4 100644 --- a/source/blender/blenkernel/intern/mask.cc +++ b/source/blender/blenkernel/intern/mask.cc @@ -336,12 +336,7 @@ MaskLayer *BKE_mask_layer_new(Mask *mask, const char *name) { MaskLayer *masklay = MEM_cnew(__func__); - if (name && name[0]) { - STRNCPY(masklay->name, name); - } - else { - strcpy(masklay->name, DATA_("MaskLayer")); - } + STRNCPY(masklay->name, name && name[0] ? name : DATA_("MaskLayer")); BLI_addtail(&mask->masklayers, masklay); @@ -1011,12 +1006,7 @@ Mask *BKE_mask_new(Main *bmain, const char *name) Mask *mask; char mask_name[MAX_ID_NAME - 2]; - if (name && name[0]) { - STRNCPY(mask_name, name); - } - else { - strcpy(mask_name, "Mask"); - } + STRNCPY(mask_name, (name && name[0]) ? name : "Mask"); mask = mask_alloc(bmain, mask_name); @@ -2040,7 +2030,7 @@ void BKE_mask_clipboard_copy_from_layer(MaskLayer *mask_layer) if (!BLI_ghash_lookup(mask_clipboard.id_hash, point->parent.id)) { int len = strlen(point->parent.id->name); char *name_copy = static_cast(MEM_mallocN(len + 1, "mask clipboard ID name")); - strcpy(name_copy, point->parent.id->name); + memcpy(name_copy, point->parent.id->name, len + 1); BLI_ghash_insert(mask_clipboard.id_hash, point->parent.id, name_copy); } } diff --git a/source/blender/blenkernel/intern/mesh_tangent.cc b/source/blender/blenkernel/intern/mesh_tangent.cc index e21d0dfcca0..e941a27f707 100644 --- a/source/blender/blenkernel/intern/mesh_tangent.cc +++ b/source/blender/blenkernel/intern/mesh_tangent.cc @@ -338,14 +338,16 @@ void BKE_mesh_calc_loop_tangent_step_0(const CustomData *loopData, *ract_uv_n = CustomData_get_active_layer(loopData, CD_PROP_FLOAT2); ract_uv_name[0] = 0; if (*ract_uv_n != -1) { - strcpy(ract_uv_name, loopData->layers[*ract_uv_n + layer_index].name); + BLI_strncpy( + ract_uv_name, loopData->layers[*ract_uv_n + layer_index].name, MAX_CUSTOMDATA_LAYER_NAME); } /* Active tangent in render */ *rren_uv_n = CustomData_get_render_layer(loopData, CD_PROP_FLOAT2); rren_uv_name[0] = 0; if (*rren_uv_n != -1) { - strcpy(rren_uv_name, loopData->layers[*rren_uv_n + layer_index].name); + BLI_strncpy( + rren_uv_name, loopData->layers[*rren_uv_n + layer_index].name, MAX_CUSTOMDATA_LAYER_NAME); } /* If active tangent not in tangent_names we take it into account */ diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c index cb6226ab373..ed0bfa2c636 100644 --- a/source/blender/blenkernel/intern/nla.c +++ b/source/blender/blenkernel/intern/nla.c @@ -367,7 +367,7 @@ void BKE_nlatrack_insert_before(ListBase *nla_tracks, new_track->index = BLI_findindex(nla_tracks, new_track); /* Must have unique name, but we need to seed this. */ - strcpy(new_track->name, "NlaTrack"); + STRNCPY(new_track->name, "NlaTrack"); BLI_uniquename(nla_tracks, new_track, diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 5ce69f1acf0..3f9fa2a0baa 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -1424,14 +1424,15 @@ static int ptcache_filepath(PTCacheID *pid, idname = (pid->owner_id->name + 2); /* convert chars to hex so they are always a valid filename */ while ('\0' != *idname) { - BLI_snprintf(newname, MAX_PTCACHE_FILE - len, "%02X", (uint)(*idname++)); - newname += 2; - len += 2; + /* Always 2 unless there isn't enough room in the string. */ + const int temp = BLI_snprintf_rlen( + newname, MAX_PTCACHE_FILE - len, "%02X", (uint)(*idname++)); + newname += temp; + len += temp; } } else { - int temp = (int)strlen(pid->cache->name); - strcpy(newname, pid->cache->name); + int temp = BLI_strncpy_rlen(newname, pid->cache->name, MAX_PTCACHE_FILE - len); newname += temp; len += temp; } diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 10c7f0bcca0..404d30a6c78 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -462,8 +462,7 @@ bSound *BKE_sound_new_buffer(Main *bmain, bSound *source) bSound *sound = NULL; char name[MAX_ID_NAME + 5]; - strcpy(name, "buf_"); - strcpy(name + 4, source->id.name); + BLI_string_join(name, sizeof(name), "buf_", source->id.name); sound = BKE_libblock_alloc(bmain, ID_SO, name); @@ -480,8 +479,7 @@ bSound *BKE_sound_new_limiter(Main *bmain, bSound *source, float start, float en bSound *sound = NULL; char name[MAX_ID_NAME + 5]; - strcpy(name, "lim_"); - strcpy(name + 4, source->id.name); + BLI_string_join(name, sizeof(name), "lim_", source->id.name); sound = BKE_libblock_alloc(bmain, ID_SO, name); diff --git a/source/blender/blenkernel/intern/tracking.cc b/source/blender/blenkernel/intern/tracking.cc index 4bf1f108b45..d6e5cc3c8b0 100644 --- a/source/blender/blenkernel/intern/tracking.cc +++ b/source/blender/blenkernel/intern/tracking.cc @@ -499,7 +499,7 @@ MovieTrackingTrack *BKE_tracking_track_add_empty(MovieTracking *tracking, ListBa const MovieTrackingSettings *settings = &tracking->settings; MovieTrackingTrack *track = MEM_cnew("add_marker_exec track"); - strcpy(track->name, "Track"); + STRNCPY(track->name, "Track"); /* Fill track's settings from default settings. */ track->motion_model = settings->default_motion_model; @@ -1579,7 +1579,7 @@ MovieTrackingPlaneTrack *BKE_tracking_plane_track_add(MovieTracking *tracking, plane_track = MEM_cnew("new plane track"); /* Use some default name. */ - strcpy(plane_track->name, "Plane Track"); + STRNCPY(plane_track->name, "Plane Track"); plane_track->image_opacity = 1.0f; diff --git a/source/blender/blenkernel/intern/vfont.c b/source/blender/blenkernel/intern/vfont.c index 396d7965855..2a64e422947 100644 --- a/source/blender/blenkernel/intern/vfont.c +++ b/source/blender/blenkernel/intern/vfont.c @@ -295,7 +295,7 @@ static VFontData *vfont_get_data(VFont *vfont) /* DON'T DO THIS * missing file shouldn't modify path! - campbell */ #if 0 - strcpy(vfont->filepath, FO_BUILTIN_NAME); + STRNCPY(vfont->filepath, FO_BUILTIN_NAME); #endif pf = get_builtin_packedfile(); } diff --git a/source/blender/blenlib/intern/BLI_filelist.c b/source/blender/blenlib/intern/BLI_filelist.c index af1d0548acc..290b7607f09 100644 --- a/source/blender/blenlib/intern/BLI_filelist.c +++ b/source/blender/blenlib/intern/BLI_filelist.c @@ -15,7 +15,7 @@ # include #endif -#include /* #strcpy etc. */ +#include #include #include @@ -320,7 +320,7 @@ void BLI_filelist_entry_owner_to_string(const struct stat *st, { #ifdef WIN32 UNUSED_VARS(st); - strcpy(r_owner, "unknown"); + BLI_strncpy(r_owner, "unknown", FILELIST_DIRENTRY_OWNER_LEN); #else struct passwd *pwuser = getpwuid(st->st_uid); diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index f2955a14e2e..7d3b6f4c095 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -793,7 +793,7 @@ void BLI_path_rel(char path[FILE_MAX], const char *basepath) #ifdef WIN32 BLI_str_replace_char(res + 2, '/', '\\'); #endif - strcpy(path, res); + BLI_strncpy(path, res, FILE_MAX); } } diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c index 5915a5034b9..0215b8695c6 100644 --- a/source/blender/blenlib/intern/storage.c +++ b/source/blender/blenlib/intern/storage.c @@ -32,7 +32,7 @@ #endif #include -#include /* `strcpy` etc. */ +#include #ifdef WIN32 # include "BLI_string_utf8.h" @@ -145,16 +145,17 @@ double BLI_dir_free_space(const char *dir) return -1; } - strcpy(dirname, dir); + memcpy(dirname, dir, len + 1); if (len) { slash = strrchr(dirname, '/'); if (slash) { - slash[1] = 0; + slash[1] = '\0'; } } else { - strcpy(dirname, "/"); + dirname[0] = '/'; + dirname[1] = '\0'; } # if defined(USE_STATFS_STATVFS) diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c index 67f0c0e0f83..bbe14f0d04f 100644 --- a/source/blender/blenloader/intern/versioning_250.c +++ b/source/blender/blenloader/intern/versioning_250.c @@ -716,7 +716,7 @@ void blo_do_versions_250(FileData *fd, Library *UNUSED(lib), Main *bmain) */ for (ma = bmain->materials.first; ma; ma = ma->id.next) { if (ma->nodetree && ma->nodetree->id.name[0] == '\0') { - strcpy(ma->nodetree->id.name, "NTShader Nodetree"); + STRNCPY(ma->nodetree->id.name, "NTShader Nodetree"); } } @@ -724,7 +724,7 @@ void blo_do_versions_250(FileData *fd, Library *UNUSED(lib), Main *bmain) for (sce = bmain->scenes.first; sce; sce = sce->id.next) { enum { R_PANORAMA = (1 << 10) }; if (sce->nodetree && sce->nodetree->id.name[0] == '\0') { - strcpy(sce->nodetree->id.name, "NTCompositing Nodetree"); + STRNCPY(sce->nodetree->id.name, "NTCompositing Nodetree"); } /* move to cameras */ @@ -748,7 +748,7 @@ void blo_do_versions_250(FileData *fd, Library *UNUSED(lib), Main *bmain) if (tx->nodetree) { if (tx->nodetree->id.name[0] == '\0') { - strcpy(tx->nodetree->id.name, "NTTexture Nodetree"); + STRNCPY(tx->nodetree->id.name, "NTTexture Nodetree"); } /* which_output 0 is now "not specified" */ @@ -2315,7 +2315,7 @@ static void lib_node_do_versions_group_indices(bNode *gnode) for (link = ngroup->links.first; link; link = link->next) { if (link->tonode == NULL && link->fromsock->own_index == old_index) { - strcpy(sock->identifier, link->fromsock->identifier); + STRNCPY(sock->identifier, link->fromsock->identifier); /* deprecated */ sock->own_index = link->fromsock->own_index; sock->to_index = 0; @@ -2327,7 +2327,7 @@ static void lib_node_do_versions_group_indices(bNode *gnode) for (link = ngroup->links.first; link; link = link->next) { if (link->fromnode == NULL && link->tosock->own_index == old_index) { - strcpy(sock->identifier, link->tosock->identifier); + STRNCPY(sock->identifier, link->tosock->identifier); /* deprecated */ sock->own_index = link->tosock->own_index; sock->to_index = 0; diff --git a/source/blender/blenloader/intern/versioning_260.c b/source/blender/blenloader/intern/versioning_260.c index 4416f7f89d6..fa12bb4c5b8 100644 --- a/source/blender/blenloader/intern/versioning_260.c +++ b/source/blender/blenloader/intern/versioning_260.c @@ -551,13 +551,13 @@ static void do_versions_nodetree_customnodes(bNodeTree *ntree, int UNUSED(is_gro /* tree type idname */ switch (ntree->type) { case NTREE_COMPOSIT: - strcpy(ntree->idname, "CompositorNodeTree"); + STRNCPY(ntree->idname, "CompositorNodeTree"); break; case NTREE_SHADER: - strcpy(ntree->idname, "ShaderNodeTree"); + STRNCPY(ntree->idname, "ShaderNodeTree"); break; case NTREE_TEXTURE: - strcpy(ntree->idname, "TextureNodeTree"); + STRNCPY(ntree->idname, "TextureNodeTree"); break; } @@ -1947,13 +1947,13 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) /* convert deprecated treetype setting to tree_idname */ switch (snode->treetype) { case NTREE_COMPOSIT: - strcpy(snode->tree_idname, "CompositorNodeTree"); + STRNCPY(snode->tree_idname, "CompositorNodeTree"); break; case NTREE_SHADER: - strcpy(snode->tree_idname, "ShaderNodeTree"); + STRNCPY(snode->tree_idname, "ShaderNodeTree"); break; case NTREE_TEXTURE: - strcpy(snode->tree_idname, "TextureNodeTree"); + STRNCPY(snode->tree_idname, "TextureNodeTree"); break; } } diff --git a/source/blender/blenloader/intern/versioning_300.cc b/source/blender/blenloader/intern/versioning_300.cc index cc2ee620b57..741baf6f938 100644 --- a/source/blender/blenloader/intern/versioning_300.cc +++ b/source/blender/blenloader/intern/versioning_300.cc @@ -1363,7 +1363,7 @@ static void version_switch_node_input_prefix(Main *bmain) if (socket == node->inputs.first) { continue; } - strcpy(socket->name, socket->name[0] == 'A' ? "False" : "True"); + STRNCPY(socket->name, socket->name[0] == 'A' ? "False" : "True"); /* Replace "A" and "B", but keep the unique number suffix at the end. */ char number_suffix[8]; @@ -1940,7 +1940,7 @@ static void versioning_replace_legacy_combined_and_separate_color_nodes(bNodeTre NodeCombSepColor *storage = (NodeCombSepColor *)MEM_callocN(sizeof(NodeCombSepColor), __func__); storage->mode = NODE_COMBSEP_COLOR_RGB; - strcpy(node->idname, "FunctionNodeCombineColor"); + STRNCPY(node->idname, "FunctionNodeCombineColor"); node->storage = storage; break; } @@ -1949,7 +1949,7 @@ static void versioning_replace_legacy_combined_and_separate_color_nodes(bNodeTre NodeCombSepColor *storage = (NodeCombSepColor *)MEM_callocN(sizeof(NodeCombSepColor), __func__); storage->mode = NODE_COMBSEP_COLOR_RGB; - strcpy(node->idname, "FunctionNodeSeparateColor"); + STRNCPY(node->idname, "FunctionNodeSeparateColor"); node->storage = storage; break; } @@ -2007,7 +2007,7 @@ static void versioning_replace_legacy_combined_and_separate_color_nodes(bNodeTre NodeCMPCombSepColor *storage = (NodeCMPCombSepColor *)MEM_callocN( sizeof(NodeCMPCombSepColor), __func__); storage->mode = CMP_NODE_COMBSEP_COLOR_RGB; - strcpy(node->idname, "CompositorNodeCombineColor"); + STRNCPY(node->idname, "CompositorNodeCombineColor"); node->storage = storage; break; } @@ -2016,7 +2016,7 @@ static void versioning_replace_legacy_combined_and_separate_color_nodes(bNodeTre NodeCMPCombSepColor *storage = (NodeCMPCombSepColor *)MEM_callocN( sizeof(NodeCMPCombSepColor), __func__); storage->mode = CMP_NODE_COMBSEP_COLOR_HSV; - strcpy(node->idname, "CompositorNodeCombineColor"); + STRNCPY(node->idname, "CompositorNodeCombineColor"); node->storage = storage; break; } @@ -2026,7 +2026,7 @@ static void versioning_replace_legacy_combined_and_separate_color_nodes(bNodeTre sizeof(NodeCMPCombSepColor), __func__); storage->mode = CMP_NODE_COMBSEP_COLOR_YCC; storage->ycc_mode = node->custom1; - strcpy(node->idname, "CompositorNodeCombineColor"); + STRNCPY(node->idname, "CompositorNodeCombineColor"); node->storage = storage; break; } @@ -2035,7 +2035,7 @@ static void versioning_replace_legacy_combined_and_separate_color_nodes(bNodeTre NodeCMPCombSepColor *storage = (NodeCMPCombSepColor *)MEM_callocN( sizeof(NodeCMPCombSepColor), __func__); storage->mode = CMP_NODE_COMBSEP_COLOR_YUV; - strcpy(node->idname, "CompositorNodeCombineColor"); + STRNCPY(node->idname, "CompositorNodeCombineColor"); node->storage = storage; break; } @@ -2044,7 +2044,7 @@ static void versioning_replace_legacy_combined_and_separate_color_nodes(bNodeTre NodeCMPCombSepColor *storage = (NodeCMPCombSepColor *)MEM_callocN( sizeof(NodeCMPCombSepColor), __func__); storage->mode = CMP_NODE_COMBSEP_COLOR_RGB; - strcpy(node->idname, "CompositorNodeSeparateColor"); + STRNCPY(node->idname, "CompositorNodeSeparateColor"); node->storage = storage; break; } @@ -2053,7 +2053,7 @@ static void versioning_replace_legacy_combined_and_separate_color_nodes(bNodeTre NodeCMPCombSepColor *storage = (NodeCMPCombSepColor *)MEM_callocN( sizeof(NodeCMPCombSepColor), __func__); storage->mode = CMP_NODE_COMBSEP_COLOR_HSV; - strcpy(node->idname, "CompositorNodeSeparateColor"); + STRNCPY(node->idname, "CompositorNodeSeparateColor"); node->storage = storage; break; } @@ -2063,7 +2063,7 @@ static void versioning_replace_legacy_combined_and_separate_color_nodes(bNodeTre sizeof(NodeCMPCombSepColor), __func__); storage->mode = CMP_NODE_COMBSEP_COLOR_YCC; storage->ycc_mode = node->custom1; - strcpy(node->idname, "CompositorNodeSeparateColor"); + STRNCPY(node->idname, "CompositorNodeSeparateColor"); node->storage = storage; break; } @@ -2072,7 +2072,7 @@ static void versioning_replace_legacy_combined_and_separate_color_nodes(bNodeTre NodeCMPCombSepColor *storage = (NodeCMPCombSepColor *)MEM_callocN( sizeof(NodeCMPCombSepColor), __func__); storage->mode = CMP_NODE_COMBSEP_COLOR_YUV; - strcpy(node->idname, "CompositorNodeSeparateColor"); + STRNCPY(node->idname, "CompositorNodeSeparateColor"); node->storage = storage; break; } @@ -2087,13 +2087,13 @@ static void versioning_replace_legacy_combined_and_separate_color_nodes(bNodeTre case TEX_NODE_COMPOSE_LEGACY: { node->type = TEX_NODE_COMBINE_COLOR; node->custom1 = NODE_COMBSEP_COLOR_RGB; - strcpy(node->idname, "TextureNodeCombineColor"); + STRNCPY(node->idname, "TextureNodeCombineColor"); break; } case TEX_NODE_DECOMPOSE_LEGACY: { node->type = TEX_NODE_SEPARATE_COLOR; node->custom1 = NODE_COMBSEP_COLOR_RGB; - strcpy(node->idname, "TextureNodeSeparateColor"); + STRNCPY(node->idname, "TextureNodeSeparateColor"); break; } } @@ -2127,7 +2127,7 @@ static void versioning_replace_legacy_combined_and_separate_color_nodes(bNodeTre NodeCombSepColor *storage = (NodeCombSepColor *)MEM_callocN(sizeof(NodeCombSepColor), __func__); storage->mode = NODE_COMBSEP_COLOR_RGB; - strcpy(node->idname, "ShaderNodeCombineColor"); + STRNCPY(node->idname, "ShaderNodeCombineColor"); node->storage = storage; break; } @@ -2136,7 +2136,7 @@ static void versioning_replace_legacy_combined_and_separate_color_nodes(bNodeTre NodeCombSepColor *storage = (NodeCombSepColor *)MEM_callocN(sizeof(NodeCombSepColor), __func__); storage->mode = NODE_COMBSEP_COLOR_HSV; - strcpy(node->idname, "ShaderNodeCombineColor"); + STRNCPY(node->idname, "ShaderNodeCombineColor"); node->storage = storage; break; } @@ -2145,7 +2145,7 @@ static void versioning_replace_legacy_combined_and_separate_color_nodes(bNodeTre NodeCombSepColor *storage = (NodeCombSepColor *)MEM_callocN(sizeof(NodeCombSepColor), __func__); storage->mode = NODE_COMBSEP_COLOR_RGB; - strcpy(node->idname, "ShaderNodeSeparateColor"); + STRNCPY(node->idname, "ShaderNodeSeparateColor"); node->storage = storage; break; } @@ -2154,7 +2154,7 @@ static void versioning_replace_legacy_combined_and_separate_color_nodes(bNodeTre NodeCombSepColor *storage = (NodeCombSepColor *)MEM_callocN(sizeof(NodeCombSepColor), __func__); storage->mode = NODE_COMBSEP_COLOR_HSV; - strcpy(node->idname, "ShaderNodeSeparateColor"); + STRNCPY(node->idname, "ShaderNodeSeparateColor"); node->storage = storage; break; } @@ -2171,7 +2171,7 @@ static void versioning_replace_legacy_mix_rgb_node(bNodeTree *ntree) version_node_output_socket_name(ntree, SH_NODE_MIX_RGB_LEGACY, "Color", "Result_Color"); LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->type == SH_NODE_MIX_RGB_LEGACY) { - strcpy(node->idname, "ShaderNodeMix"); + STRNCPY(node->idname, "ShaderNodeMix"); node->type = SH_NODE_MIX; NodeShaderMix *data = (NodeShaderMix *)MEM_callocN(sizeof(NodeShaderMix), __func__); data->blend_type = node->custom1; @@ -2570,7 +2570,7 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) if (ntree->type == NTREE_GEOMETRY) { LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->type == GEO_NODE_SUBDIVIDE_MESH) { - strcpy(node->idname, "GeometryNodeMeshSubdivide"); + STRNCPY(node->idname, "GeometryNodeMeshSubdivide"); } } } @@ -3266,7 +3266,7 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) sizeof(NodeFunctionCompare), __func__); data->data_type = SOCK_FLOAT; data->operation = node->custom1; - strcpy(node->idname, "FunctionNodeCompare"); + STRNCPY(node->idname, "FunctionNodeCompare"); node->storage = data; } } diff --git a/source/blender/blenloader/intern/versioning_400.cc b/source/blender/blenloader/intern/versioning_400.cc index 071fe64f393..e0f986d145c 100644 --- a/source/blender/blenloader/intern/versioning_400.cc +++ b/source/blender/blenloader/intern/versioning_400.cc @@ -164,7 +164,7 @@ static void versioning_replace_legacy_glossy_node(bNodeTree *ntree) { LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->type == SH_NODE_BSDF_GLOSSY_LEGACY) { - strcpy(node->idname, "ShaderNodeBsdfAnisotropic"); + STRNCPY(node->idname, "ShaderNodeBsdfAnisotropic"); node->type = SH_NODE_BSDF_GLOSSY; } } diff --git a/source/blender/blenloader/intern/versioning_common.cc b/source/blender/blenloader/intern/versioning_common.cc index b6e82c01232..bf00cce0346 100644 --- a/source/blender/blenloader/intern/versioning_common.cc +++ b/source/blender/blenloader/intern/versioning_common.cc @@ -191,7 +191,7 @@ void version_node_id(bNodeTree *ntree, const int node_type, const char *new_name for (bNode *node : ntree->all_nodes()) { if (node->type == node_type) { if (!STREQ(node->idname, new_name)) { - strcpy(node->idname, new_name); + STRNCPY(node->idname, new_name); } } } diff --git a/source/blender/blenloader/intern/versioning_cycles.c b/source/blender/blenloader/intern/versioning_cycles.c index 7f815ed5d76..a37c1015cb7 100644 --- a/source/blender/blenloader/intern/versioning_cycles.c +++ b/source/blender/blenloader/intern/versioning_cycles.c @@ -1040,8 +1040,8 @@ static void update_voronoi_node_fac_output(bNodeTree *ntree) LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->type == SH_NODE_TEX_VORONOI) { bNodeSocket *facOutput = BLI_findlink(&node->outputs, 1); - strcpy(facOutput->identifier, "Distance"); - strcpy(facOutput->name, "Distance"); + STRNCPY(facOutput->identifier, "Distance"); + STRNCPY(facOutput->name, "Distance"); } } } diff --git a/source/blender/blenloader/intern/versioning_legacy.c b/source/blender/blenloader/intern/versioning_legacy.c index 64a4486437b..b129c5905d4 100644 --- a/source/blender/blenloader/intern/versioning_legacy.c +++ b/source/blender/blenloader/intern/versioning_legacy.c @@ -324,7 +324,7 @@ static void customdata_version_242(Mesh *me) if (layer->type == CD_MTFACE) { if (layer->name[0] == 0) { if (mtfacen == 0) { - strcpy(layer->name, "UVMap"); + STRNCPY(layer->name, "UVMap"); } else { SNPRINTF(layer->name, "UVMap.%.3d", mtfacen); @@ -335,7 +335,7 @@ static void customdata_version_242(Mesh *me) else if (layer->type == CD_MCOL) { if (layer->name[0] == 0) { if (mcoln == 0) { - strcpy(layer->name, "Col"); + STRNCPY(layer->name, "Col"); } else { SNPRINTF(layer->name, "Col.%.3d", mcoln); @@ -843,7 +843,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) VFont *vf; for (vf = bmain->fonts.first; vf; vf = vf->id.next) { if (BLI_str_endswith(vf->filepath, ".Bfont")) { - strcpy(vf->filepath, FO_BUILTIN_NAME); + STRNCPY(vf->filepath, FO_BUILTIN_NAME); } } } @@ -1476,7 +1476,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) for (kb = key->block.first; kb; kb = kb->next) { if (kb == key->refkey) { if (kb->name[0] == 0) { - strcpy(kb->name, "Basis"); + STRNCPY(kb->name, "Basis"); } } else { @@ -1611,8 +1611,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) Image *ima; for (ima = bmain->images.first; ima; ima = ima->id.next) { if (STREQ(ima->filepath, "Compositor")) { - strcpy(ima->id.name + 2, "Viewer Node"); - strcpy(ima->filepath, "Viewer Node"); + BLI_strncpy(ima->id.name + 2, "Viewer Node", sizeof(ima->id.name) - 2); + STRNCPY(ima->filepath, "Viewer Node"); } } } diff --git a/source/blender/blenloader/intern/versioning_userdef.c b/source/blender/blenloader/intern/versioning_userdef.c index 0268a6130bf..c68aefa2a13 100644 --- a/source/blender/blenloader/intern/versioning_userdef.c +++ b/source/blender/blenloader/intern/versioning_userdef.c @@ -237,7 +237,7 @@ void blo_do_versions_userdef(UserDef *userdef) } if (!USER_VERSION_ATLEAST(192, 0)) { - strcpy(userdef->sounddir, "/"); + STRNCPY(userdef->sounddir, "/"); } /* patch to set Dupli Armature */ @@ -311,52 +311,52 @@ void blo_do_versions_userdef(UserDef *userdef) for (km = userdef->user_keymaps.first; km; km = km->next) { if (STREQ(km->idname, "Armature_Sketch")) { - strcpy(km->idname, "Armature Sketch"); + STRNCPY(km->idname, "Armature Sketch"); } else if (STREQ(km->idname, "View3D")) { - strcpy(km->idname, "3D View"); + STRNCPY(km->idname, "3D View"); } else if (STREQ(km->idname, "View3D Generic")) { - strcpy(km->idname, "3D View Generic"); + STRNCPY(km->idname, "3D View Generic"); } else if (STREQ(km->idname, "EditMesh")) { - strcpy(km->idname, "Mesh"); + STRNCPY(km->idname, "Mesh"); } else if (STREQ(km->idname, "UVEdit")) { - strcpy(km->idname, "UV Editor"); + STRNCPY(km->idname, "UV Editor"); } else if (STREQ(km->idname, "Animation_Channels")) { - strcpy(km->idname, "Animation Channels"); + STRNCPY(km->idname, "Animation Channels"); } else if (STREQ(km->idname, "GraphEdit Keys")) { - strcpy(km->idname, "Graph Editor"); + STRNCPY(km->idname, "Graph Editor"); } else if (STREQ(km->idname, "GraphEdit Generic")) { - strcpy(km->idname, "Graph Editor Generic"); + STRNCPY(km->idname, "Graph Editor Generic"); } else if (STREQ(km->idname, "Action_Keys")) { - strcpy(km->idname, "Dopesheet"); + STRNCPY(km->idname, "Dopesheet"); } else if (STREQ(km->idname, "NLA Data")) { - strcpy(km->idname, "NLA Editor"); + STRNCPY(km->idname, "NLA Editor"); } else if (STREQ(km->idname, "Node Generic")) { - strcpy(km->idname, "Node Editor"); + STRNCPY(km->idname, "Node Editor"); } else if (STREQ(km->idname, "Logic Generic")) { - strcpy(km->idname, "Logic Editor"); + STRNCPY(km->idname, "Logic Editor"); } else if (STREQ(km->idname, "File")) { - strcpy(km->idname, "File Browser"); + STRNCPY(km->idname, "File Browser"); } else if (STREQ(km->idname, "FileMain")) { - strcpy(km->idname, "File Browser Main"); + STRNCPY(km->idname, "File Browser Main"); } else if (STREQ(km->idname, "FileButtons")) { - strcpy(km->idname, "File Browser Buttons"); + STRNCPY(km->idname, "File Browser Buttons"); } else if (STREQ(km->idname, "Buttons Generic")) { - strcpy(km->idname, "Property Editor"); + STRNCPY(km->idname, "Property Editor"); } } } diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp index a5aee76954b..d170f2c68e4 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp +++ b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp @@ -104,7 +104,7 @@ BlenderStrokeRenderer::BlenderStrokeRenderer(Render *re, int render_count) freestyle_scene->r.border.ymin = old_scene->r.border.ymin; freestyle_scene->r.border.xmax = old_scene->r.border.xmax; freestyle_scene->r.border.ymax = old_scene->r.border.ymax; - strcpy(freestyle_scene->r.pic, old_scene->r.pic); + STRNCPY(freestyle_scene->r.pic, old_scene->r.pic); freestyle_scene->r.dither_intensity = old_scene->r.dither_intensity; STRNCPY(freestyle_scene->r.engine, old_scene->r.engine); if (G.debug & G_DEBUG_FREESTYLE) { diff --git a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp index 2f7e61c4db4..b717ef88a93 100644 --- a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp +++ b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp @@ -708,7 +708,7 @@ void FRS_copy_active_lineset(FreestyleConfig *config) lineset_buffer.edge_types = lineset->edge_types; lineset_buffer.exclude_edge_types = lineset->exclude_edge_types; lineset_buffer.group = lineset->group; - strcpy(lineset_buffer.name, lineset->name); + STRNCPY(lineset_buffer.name, lineset->name); lineset_copied = true; } } @@ -744,7 +744,7 @@ void FRS_paste_active_lineset(FreestyleConfig *config) lineset->group = lineset_buffer.group; id_us_plus(&lineset->group->id); } - strcpy(lineset->name, lineset_buffer.name); + STRNCPY(lineset->name, lineset_buffer.name); BKE_freestyle_lineset_unique_name(config, lineset); lineset->flags |= FREESTYLE_LINESET_CURRENT; } diff --git a/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_dash.c b/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_dash.c index 620c86534d3..112a97d248d 100644 --- a/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_dash.c +++ b/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_dash.c @@ -366,7 +366,7 @@ static void panelRegister(ARegionType *region_type) region_type, "mask", "Influence", NULL, mask_panel_draw, panel_type); uiListType *list_type = MEM_callocN(sizeof(uiListType), "dash modifier segment uilist"); - strcpy(list_type->idname, "MOD_UL_dash_segment"); + STRNCPY(list_type->idname, "MOD_UL_dash_segment"); list_type->draw_item = segment_list_item; WM_uilisttype_add(list_type); } diff --git a/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_time.c b/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_time.c index f032644a53e..cf89a709e12 100644 --- a/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_time.c +++ b/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_time.c @@ -417,7 +417,7 @@ static void panelRegister(ARegionType *region_type) region_type, "mask", "Influence", NULL, mask_panel_draw, panel_type); uiListType *list_type = MEM_callocN(sizeof(uiListType), "time modifier segment uilist"); - strcpy(list_type->idname, "MOD_UL_time_segment"); + STRNCPY(list_type->idname, "MOD_UL_time_segment"); list_type->draw_item = segment_list_item; WM_uilisttype_add(list_type); } diff --git a/source/blender/imbuf/intern/cineon/dpxlib.cc b/source/blender/imbuf/intern/cineon/dpxlib.cc index 9a41e8cde1e..2fe58d7bcf6 100644 --- a/source/blender/imbuf/intern/cineon/dpxlib.cc +++ b/source/blender/imbuf/intern/cineon/dpxlib.cc @@ -52,7 +52,7 @@ static void fillDpxMainHeader(LogImageFile *dpx, /* --- File header --- */ header->fileHeader.magic_num = swap_uint(DPX_FILE_MAGIC, dpx->isMSB); header->fileHeader.offset = swap_uint(dpx->element[0].dataOffset, dpx->isMSB); - strcpy(header->fileHeader.version, "V2.0"); + STRNCPY(header->fileHeader.version, "V2.0"); header->fileHeader.file_size = swap_uint( dpx->element[0].dataOffset + dpx->height * getRowLength(dpx->width, dpx->element[0]), dpx->isMSB); diff --git a/source/blender/imbuf/intern/jpeg.cc b/source/blender/imbuf/intern/jpeg.cc index 6687b809a6c..b9ac040ec2b 100644 --- a/source/blender/imbuf/intern/jpeg.cc +++ b/source/blender/imbuf/intern/jpeg.cc @@ -567,7 +567,7 @@ static void write_jpeg(jpeg_compress_struct *cinfo, ImBuf *ibuf) jpeg_start_compress(cinfo, true); - strcpy(neogeo, "NeoGeo"); + STRNCPY(neogeo, "NeoGeo"); neogeo_word = (NeoGeo_Word *)(neogeo + 6); memset(neogeo_word, 0, sizeof(*neogeo_word)); neogeo_word->quality = ibuf->foptions.quality; diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp index e8d9d564323..3cbee38f7ad 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.cpp +++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp @@ -1480,6 +1480,8 @@ static int imb_exr_split_token(const char *str, const char *end, const char **to static int imb_exr_split_channel_name(ExrChannel *echan, char *layname, char *passname) { + const int layname_maxncpy = EXR_TOT_MAXNAME; + const int passname_maxncpy = EXR_TOT_MAXNAME; const char *name = echan->m->name.c_str(); const char *end = name + strlen(name); const char *token; @@ -1490,13 +1492,13 @@ static int imb_exr_split_channel_name(ExrChannel *echan, char *layname, char *pa layname[0] = '\0'; if (ELEM(name[0], 'R', 'G', 'B', 'A')) { - strcpy(passname, "Combined"); + BLI_strncpy(passname, "Combined", passname_maxncpy); } else if (name[0] == 'Z') { - strcpy(passname, "Depth"); + BLI_strncpy(passname, "Depth", passname_maxncpy); } else { - strcpy(passname, name); + BLI_strncpy(passname, name, passname_maxncpy); } return 1; @@ -1565,7 +1567,7 @@ static int imb_exr_split_channel_name(ExrChannel *echan, char *layname, char *pa /* all preceding tokens combined as layer name */ if (end > name) { - BLI_strncpy(layname, name, int(end - name) + 1); + BLI_strncpy(layname, name, std::min(layname_maxncpy, int(end - name) + 1)); } else { layname[0] = '\0'; diff --git a/source/blender/io/alembic/tests/abc_export_test.cc b/source/blender/io/alembic/tests/abc_export_test.cc index 00031838669..db69d9492a8 100644 --- a/source/blender/io/alembic/tests/abc_export_test.cc +++ b/source/blender/io/alembic/tests/abc_export_test.cc @@ -34,7 +34,7 @@ class AlembicExportTest : public testing::Test { /* Fake a 25 FPS scene with a nonzero base (because that's sometimes forgotten) */ scene.r.frs_sec = 50; scene.r.frs_sec_base = 2; - strcpy(scene.id.name, "SCTestScene"); + STRNCPY(scene.id.name, "SCTestScene"); bmain = BKE_main_new(); diff --git a/source/blender/io/collada/Materials.cpp b/source/blender/io/collada/Materials.cpp index b701c87dee6..8bec979a57d 100644 --- a/source/blender/io/collada/Materials.cpp +++ b/source/blender/io/collada/Materials.cpp @@ -107,7 +107,7 @@ bNode *MaterialNode::add_node(int node_type, int locx, int locy, std::string lab bNode *node = nodeAddStaticNode(mContext, ntree, node_type); if (node) { if (label.length() > 0) { - strcpy(node->label, label.c_str()); + STRNCPY(node->label, label.c_str()); } node->locx = locx; node->locy = locy; diff --git a/source/blender/io/collada/collada_utils.cpp b/source/blender/io/collada/collada_utils.cpp index 1567414842a..94d662a279a 100644 --- a/source/blender/io/collada/collada_utils.cpp +++ b/source/blender/io/collada/collada_utils.cpp @@ -1126,7 +1126,7 @@ static bNode *bc_add_node( bNode *node = nodeAddStaticNode(C, ntree, node_type); if (node) { if (label.length() > 0) { - strcpy(node->label, label.c_str()); + STRNCPY(node->label, label.c_str()); } node->locx = locx; node->locy = locy; diff --git a/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc b/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc index 8067c91de98..fb81b3ca776 100644 --- a/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc +++ b/source/blender/io/gpencil/intern/gpencil_io_import_svg.cc @@ -78,7 +78,7 @@ bool GpencilImporterSVG::read() MEM_freeN(layer_id); layer_id = (shape->id_parent[0] == '\0') ? BLI_sprintfN("Layer_%03d", prefix) : BLI_sprintfN("%s", shape->id_parent); - strcpy(prv_id, layer_id); + STRNCPY(prv_id, layer_id); } /* Check if the layer exist and create if needed. */ diff --git a/source/blender/io/usd/intern/usd_reader_volume.cc b/source/blender/io/usd/intern/usd_reader_volume.cc index 47a236aa350..f23f362329a 100644 --- a/source/blender/io/usd/intern/usd_reader_volume.cc +++ b/source/blender/io/usd/intern/usd_reader_volume.cc @@ -4,6 +4,8 @@ #include "usd_reader_volume.h" +#include "BLI_string.h" + #include "BKE_object.h" #include "BKE_volume.h" @@ -77,7 +79,7 @@ void USDVolumeReader::read_object_data(Main *bmain, const double motionSampleTim std::string filepath = fp.GetResolvedPath(); - strcpy(volume->filepath, filepath.c_str()); + STRNCPY(volume->filepath, filepath.c_str()); } } diff --git a/source/blender/io/usd/intern/usd_writer_material.cc b/source/blender/io/usd/intern/usd_writer_material.cc index 8874abb288a..8db851790fa 100644 --- a/source/blender/io/usd/intern/usd_writer_material.cc +++ b/source/blender/io/usd/intern/usd_writer_material.cc @@ -412,7 +412,7 @@ static std::string get_in_memory_texture_filename(Image *ima) char file_name[FILE_MAX]; /* Use the image name for the file name. */ - strcpy(file_name, ima->id.name + 2); + STRNCPY(file_name, ima->id.name + 2); BKE_image_path_ext_from_imformat_ensure(file_name, sizeof(file_name), &imageFormat); @@ -432,7 +432,7 @@ static void export_in_memory_texture(Image *ima, } else { /* Use the image name for the file name. */ - strcpy(file_name, ima->id.name + 2); + STRNCPY(file_name, ima->id.name + 2); } ImBuf *imbuf = BKE_image_acquire_ibuf(ima, nullptr, nullptr); @@ -674,7 +674,7 @@ static std::string get_tex_image_asset_filepath(bNode *node, } char rel_path[FILE_MAX]; - strcpy(rel_path, path.c_str()); + STRNCPY(rel_path, path.c_str()); BLI_path_rel(rel_path, stage_path.c_str()); if (!BLI_path_is_rel(rel_path)) { diff --git a/source/blender/nodes/composite/node_composite_tree.cc b/source/blender/nodes/composite/node_composite_tree.cc index eebd3e01815..6e74c5b8940 100644 --- a/source/blender/nodes/composite/node_composite_tree.cc +++ b/source/blender/nodes/composite/node_composite_tree.cc @@ -152,11 +152,11 @@ void register_node_tree_type_cmp() bNodeTreeType *tt = ntreeType_Composite = MEM_cnew(__func__); tt->type = NTREE_COMPOSIT; - strcpy(tt->idname, "CompositorNodeTree"); - strcpy(tt->group_idname, "CompositorNodeGroup"); - strcpy(tt->ui_name, N_("Compositor")); + STRNCPY(tt->idname, "CompositorNodeTree"); + STRNCPY(tt->group_idname, "CompositorNodeGroup"); + STRNCPY(tt->ui_name, N_("Compositor")); tt->ui_icon = ICON_NODE_COMPOSITING; - strcpy(tt->ui_description, N_("Compositing nodes")); + STRNCPY(tt->ui_description, N_("Compositing nodes")); tt->foreach_nodeclass = foreach_nodeclass; tt->localize = localize; diff --git a/source/blender/nodes/geometry/node_geometry_tree.cc b/source/blender/nodes/geometry/node_geometry_tree.cc index aeeef3f2105..80caec57ac6 100644 --- a/source/blender/nodes/geometry/node_geometry_tree.cc +++ b/source/blender/nodes/geometry/node_geometry_tree.cc @@ -114,11 +114,11 @@ void register_node_tree_type_geo() bNodeTreeType *tt = ntreeType_Geometry = static_cast( MEM_callocN(sizeof(bNodeTreeType), "geometry node tree type")); tt->type = NTREE_GEOMETRY; - strcpy(tt->idname, "GeometryNodeTree"); - strcpy(tt->group_idname, "GeometryNodeGroup"); - strcpy(tt->ui_name, N_("Geometry Node Editor")); + STRNCPY(tt->idname, "GeometryNodeTree"); + STRNCPY(tt->group_idname, "GeometryNodeGroup"); + STRNCPY(tt->ui_name, N_("Geometry Node Editor")); tt->ui_icon = ICON_GEOMETRY_NODES; - strcpy(tt->ui_description, N_("Geometry nodes")); + STRNCPY(tt->ui_description, N_("Geometry nodes")); tt->rna_ext.srna = &RNA_GeometryNodeTree; tt->update = geometry_node_tree_update; tt->get_from_context = geometry_node_tree_get_from_context; diff --git a/source/blender/nodes/intern/node_register.cc b/source/blender/nodes/intern/node_register.cc index 5ed598c0a9e..845c0f9302d 100644 --- a/source/blender/nodes/intern/node_register.cc +++ b/source/blender/nodes/intern/node_register.cc @@ -29,9 +29,9 @@ static void register_undefined_types() */ blender::bke::NodeTreeTypeUndefined.type = NTREE_UNDEFINED; - strcpy(blender::bke::NodeTreeTypeUndefined.idname, "NodeTreeUndefined"); - strcpy(blender::bke::NodeTreeTypeUndefined.ui_name, N_("Undefined")); - strcpy(blender::bke::NodeTreeTypeUndefined.ui_description, N_("Undefined Node Tree Type")); + STRNCPY(blender::bke::NodeTreeTypeUndefined.idname, "NodeTreeUndefined"); + STRNCPY(blender::bke::NodeTreeTypeUndefined.ui_name, N_("Undefined")); + STRNCPY(blender::bke::NodeTreeTypeUndefined.ui_description, N_("Undefined Node Tree Type")); node_type_base_custom(&blender::bke::NodeTypeUndefined, "NodeUndefined", "Undefined", 0); blender::bke::NodeTypeUndefined.poll = node_undefined_poll; diff --git a/source/blender/nodes/shader/node_shader_tree.cc b/source/blender/nodes/shader/node_shader_tree.cc index da0aeb7f83a..80f96f02865 100644 --- a/source/blender/nodes/shader/node_shader_tree.cc +++ b/source/blender/nodes/shader/node_shader_tree.cc @@ -164,11 +164,11 @@ void register_node_tree_type_sh() bNodeTreeType *tt = ntreeType_Shader = MEM_cnew("shader node tree type"); tt->type = NTREE_SHADER; - strcpy(tt->idname, "ShaderNodeTree"); - strcpy(tt->group_idname, "ShaderNodeGroup"); - strcpy(tt->ui_name, N_("Shader Editor")); + STRNCPY(tt->idname, "ShaderNodeTree"); + STRNCPY(tt->group_idname, "ShaderNodeGroup"); + STRNCPY(tt->ui_name, N_("Shader Editor")); tt->ui_icon = ICON_NODE_MATERIAL; - strcpy(tt->ui_description, N_("Shader nodes")); + STRNCPY(tt->ui_description, N_("Shader nodes")); tt->foreach_nodeclass = foreach_nodeclass; tt->localize = localize; diff --git a/source/blender/nodes/texture/node_texture_tree.cc b/source/blender/nodes/texture/node_texture_tree.cc index 84cc9b10a36..8c9c8e33781 100644 --- a/source/blender/nodes/texture/node_texture_tree.cc +++ b/source/blender/nodes/texture/node_texture_tree.cc @@ -134,11 +134,11 @@ void register_node_tree_type_tex() bNodeTreeType *tt = ntreeType_Texture = MEM_cnew("texture node tree type"); tt->type = NTREE_TEXTURE; - strcpy(tt->idname, "TextureNodeTree"); - strcpy(tt->group_idname, "TextureNodeGroup"); - strcpy(tt->ui_name, N_("Texture Node Editor")); + STRNCPY(tt->idname, "TextureNodeTree"); + STRNCPY(tt->group_idname, "TextureNodeGroup"); + STRNCPY(tt->ui_name, N_("Texture Node Editor")); tt->ui_icon = ICON_NODE_TEXTURE; /* Defined in `drawnode.c`. */ - strcpy(tt->ui_description, N_("Texture nodes")); + STRNCPY(tt->ui_description, N_("Texture nodes")); tt->foreach_nodeclass = foreach_nodeclass; tt->update = update; diff --git a/source/blender/nodes/texture/nodes/node_texture_output.cc b/source/blender/nodes/texture/nodes/node_texture_output.cc index 4e131d1c76b..6c129c51816 100644 --- a/source/blender/nodes/texture/nodes/node_texture_output.cc +++ b/source/blender/nodes/texture/nodes/node_texture_output.cc @@ -120,7 +120,7 @@ static void init(bNodeTree * /*ntree*/, bNode *node) TexNodeOutput *tno = MEM_cnew("TEX_output"); node->storage = tno; - strcpy(tno->name, "Default"); + STRNCPY(tno->name, "Default"); unique_name(node); assign_index(node); } diff --git a/source/blender/windowmanager/xr/intern/wm_xr_action.c b/source/blender/windowmanager/xr/intern/wm_xr_action.c index 4d31f9c8059..0b954140d36 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_action.c +++ b/source/blender/windowmanager/xr/intern/wm_xr_action.c @@ -13,6 +13,7 @@ #include "BLI_listbase.h" #include "BLI_math.h" +#include "BLI_string.h" #include "GHOST_C-api.h" @@ -33,9 +34,7 @@ static wmXrActionSet *action_set_create(const char *action_set_name) { wmXrActionSet *action_set = MEM_callocN(sizeof(*action_set), __func__); - action_set->name = MEM_mallocN(strlen(action_set_name) + 1, "XrActionSet_Name"); - strcpy(action_set->name, action_set_name); - + action_set->name = BLI_strdup(action_set_name); return action_set; } @@ -70,8 +69,7 @@ static wmXrAction *action_create(const char *action_name, eXrHapticFlag haptic_flag) { wmXrAction *action = MEM_callocN(sizeof(*action), __func__); - action->name = MEM_mallocN(strlen(action_name) + 1, "XrAction_Name"); - strcpy(action->name, action_name); + action->name = BLI_strdup(action_name); action->type = type; const uint count = (uint)BLI_listbase_count(user_paths); @@ -81,9 +79,7 @@ static wmXrAction *action_create(const char *action_name, action->subaction_paths = MEM_mallocN(sizeof(*action->subaction_paths) * count, "XrAction_SubactionPaths"); LISTBASE_FOREACH_INDEX (XrUserPath *, user_path, user_paths, subaction_idx) { - action->subaction_paths[subaction_idx] = MEM_mallocN(strlen(user_path->path) + 1, - "XrAction_SubactionPath"); - strcpy(action->subaction_paths[subaction_idx], user_path->path); + action->subaction_paths[subaction_idx] = BLI_strdup(user_path->path); } size_t size; @@ -122,8 +118,7 @@ static wmXrAction *action_create(const char *action_name, if (haptic_name) { BLI_assert(is_button_action); - action->haptic_name = MEM_mallocN(strlen(haptic_name) + 1, "XrAction_HapticName"); - strcpy(action->haptic_name, haptic_name); + action->haptic_name = BLI_strdup(haptic_name); action->haptic_duration = *haptic_duration; action->haptic_frequency = *haptic_frequency; action->haptic_amplitude = *haptic_amplitude; @@ -404,7 +399,7 @@ bool WM_xr_active_action_set_set(wmXrData *xr, const char *action_set_name, bool if (delayed) { /* Save name to activate action set later, before next actions sync * (see #wm_xr_session_actions_update()). */ - strcpy(xr->runtime->session_state.active_action_set_next, action_set_name); + STRNCPY(xr->runtime->session_state.active_action_set_next, action_set_name); return true; } diff --git a/source/blender/windowmanager/xr/intern/wm_xr_session.c b/source/blender/windowmanager/xr/intern/wm_xr_session.c index 0bb002b291f..78e5225788b 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_session.c +++ b/source/blender/windowmanager/xr/intern/wm_xr_session.c @@ -16,6 +16,7 @@ #include "BLI_listbase.h" #include "BLI_math.h" +#include "BLI_string.h" #include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" @@ -1039,11 +1040,11 @@ static wmXrActionData *wm_xr_session_event_create(const char *action_set_name, bool bimanual) { wmXrActionData *data = MEM_callocN(sizeof(wmXrActionData), __func__); - strcpy(data->action_set, action_set_name); - strcpy(data->action, action->name); - strcpy(data->user_path, action->subaction_paths[subaction_idx]); + STRNCPY(data->action_set, action_set_name); + STRNCPY(data->action, action->name); + STRNCPY(data->user_path, action->subaction_paths[subaction_idx]); if (bimanual) { - strcpy(data->user_path_other, action->subaction_paths[subaction_idx_other]); + STRNCPY(data->user_path_other, action->subaction_paths[subaction_idx_other]); } data->type = action->type; @@ -1266,7 +1267,7 @@ void wm_xr_session_controller_data_populate(const wmXrAction *grip_action, wmXrController *controller = MEM_callocN(sizeof(*controller), __func__); BLI_assert(STREQ(grip_action->subaction_paths[i], aim_action->subaction_paths[i])); - strcpy(controller->subaction_path, grip_action->subaction_paths[i]); + STRNCPY(controller->subaction_path, grip_action->subaction_paths[i]); BLI_addtail(controllers, controller); }