diff options
Diffstat (limited to 'source/blender')
31 files changed, 153 insertions, 118 deletions
diff --git a/source/blender/blenkernel/intern/freestyle.c b/source/blender/blenkernel/intern/freestyle.c index a0649930dfc..28d0d1719d7 100644 --- a/source/blender/blenkernel/intern/freestyle.c +++ b/source/blender/blenkernel/intern/freestyle.c @@ -183,7 +183,7 @@ FreestyleLineSet *BKE_freestyle_lineset_add(struct Main *bmain, BLI_strncpy(lineset->name, name, sizeof(lineset->name)); } else if (lineset_index > 0) { - sprintf(lineset->name, "LineSet %i", lineset_index + 1); + BLI_snprintf(lineset->name, sizeof(lineset->name), "LineSet %i", lineset_index + 1); } else { strcpy(lineset->name, "LineSet"); diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc index eae8b454189..75e3e22afa7 100644 --- a/source/blender/blenkernel/intern/image.cc +++ b/source/blender/blenkernel/intern/image.cc @@ -3610,12 +3610,12 @@ void BKE_image_set_filepath_from_tile_number(char *filepath, } if (tile_format == UDIM_TILE_FORMAT_UDIM) { - sprintf(filepath, pattern, tile_number); + BLI_sprintf(filepath, pattern, tile_number); } else if (tile_format == UDIM_TILE_FORMAT_UVTILE) { int u = ((tile_number - 1001) % 10); int v = ((tile_number - 1001) / 10); - sprintf(filepath, pattern, u + 1, v + 1); + BLI_sprintf(filepath, pattern, u + 1, v + 1); } } diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index ad9d4e4fcca..eb0c78e9361 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -3436,7 +3436,7 @@ void ntreeRemoveSocketInterface(bNodeTree *ntree, bNodeSocket *sock) static void ntree_interface_identifier_base(bNodeTree *ntree, char *base) { /* generate a valid RNA identifier */ - sprintf(base, "NodeTreeInterface_%s", ntree->id.name + 2); + BLI_sprintf(base, "NodeTreeInterface_%s", ntree->id.name + 2); RNA_identifier_sanitize(base, false); } @@ -3462,8 +3462,8 @@ static void ntree_interface_identifier(bNodeTree *ntree, BLI_uniquename_cb( ntree_interface_unique_identifier_check, nullptr, base, '_', identifier, maxlen); - sprintf(name, "Node Tree %s Interface", ntree->id.name + 2); - sprintf(description, "Interface properties of node group %s", ntree->id.name + 2); + BLI_sprintf(name, "Node Tree %s Interface", ntree->id.name + 2); + BLI_sprintf(description, "Interface properties of node group %s", ntree->id.name + 2); } static void ntree_interface_type_create(bNodeTree *ntree) diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 868cdde6d01..5622530ea41 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -3132,15 +3132,15 @@ static void ptcache_dt_to_str(char *str, double dtime) { if (dtime > 60.0) { if (dtime > 3600.0) { - sprintf( + BLI_sprintf( str, "%ih %im %is", (int)(dtime / 3600), ((int)(dtime / 60)) % 60, ((int)dtime) % 60); } else { - sprintf(str, "%im %is", ((int)(dtime / 60)) % 60, ((int)dtime) % 60); + BLI_sprintf(str, "%im %is", ((int)(dtime / 60)) % 60, ((int)dtime) % 60); } } else { - sprintf(str, "%is", ((int)dtime) % 60); + BLI_sprintf(str, "%is", ((int)dtime) % 60); } } diff --git a/source/blender/blenkernel/intern/writeffmpeg.c b/source/blender/blenkernel/intern/writeffmpeg.c index ee827cd8cd4..1d4cbc48833 100644 --- a/source/blender/blenkernel/intern/writeffmpeg.c +++ b/source/blender/blenkernel/intern/writeffmpeg.c @@ -1370,7 +1370,7 @@ static void ffmpeg_filepath_get( if ((rd->ffcodecdata.flags & FFMPEG_AUTOSPLIT_OUTPUT) != 0) { if (context) { - sprintf(autosplit, "_%03d", context->ffmpeg_autosplit_count); + BLI_snprintf(autosplit, sizeof(autosplit), "_%03d", context->ffmpeg_autosplit_count); } } diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index 17abcf52ecc..fb02ea5fb17 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -206,6 +206,13 @@ char *BLI_sprintfN(const char *__restrict format, ...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1, 2); /** + * A wrapper around ::sprintf() which does not generate security warnings. + * + * \note Use BLI_snprintf for cases when the string size is known. + */ +int BLI_sprintf(char *__restrict str, const char *__restrict format, ...); + +/** * This roughly matches C and Python's string escaping with double quotes - `"`. * * Since every character may need escaping, diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 179a1a305d1..25549de182a 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -123,7 +123,7 @@ int BLI_path_sequence_decode(const char *string, char *head, char *tail, ushort void BLI_path_sequence_encode( char *string, const char *head, const char *tail, ushort numlen, int pic) { - sprintf(string, "%s%.*d%s", head, numlen, MAX2(0, pic), tail); + BLI_sprintf(string, "%s%.*d%s", head, numlen, MAX2(0, pic), tail); } static int BLI_path_unc_prefix_len(const char *path); /* defined below in same file */ @@ -620,7 +620,7 @@ bool BLI_path_suffix(char *string, size_t maxlen, const char *suffix, const char } BLI_strncpy(extension, string + a, sizeof(extension)); - sprintf(string + a, "%s%s%s", sep, suffix, extension); + BLI_sprintf(string + a, "%s%s%s", sep, suffix, extension); return true; } diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index 755d2dbd55d..3c3dcaf90f4 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -241,6 +241,17 @@ char *BLI_sprintfN(const char *__restrict format, ...) return n; } +int BLI_sprintf(char *__restrict str, const char *__restrict format, ...) +{ + va_list arg; + + va_start(arg, format); + const int result = vsprintf(str, format, arg); + va_end(arg); + + return result; +} + /** \} */ /* -------------------------------------------------------------------- */ @@ -1114,7 +1125,7 @@ static size_t BLI_str_format_int_grouped_ex(char src[16], char dst[16], int num_ size_t BLI_str_format_int_grouped(char dst[16], int num) { char src[16]; - int num_len = sprintf(src, "%d", num); + const int num_len = BLI_snprintf(src, sizeof(src), "%d", num); return BLI_str_format_int_grouped_ex(src, dst, num_len); } @@ -1124,7 +1135,7 @@ size_t BLI_str_format_uint64_grouped(char dst[16], uint64_t num) /* NOTE: Buffer to hold maximum `uint64`, which is 1.8e+19. but * we also need space for commas and null-terminator. */ char src[27]; - int num_len = sprintf(src, "%" PRIu64 "", num); + const int num_len = BLI_snprintf(src, sizeof(src), "%" PRIu64 "", num); return BLI_str_format_int_grouped_ex(src, dst, num_len); } diff --git a/source/blender/blenlib/intern/uuid.cc b/source/blender/blenlib/intern/uuid.cc index 023dd1ec409..b845208f0da 100644 --- a/source/blender/blenlib/intern/uuid.cc +++ b/source/blender/blenlib/intern/uuid.cc @@ -5,6 +5,7 @@ */ #include "BLI_assert.h" +#include "BLI_string.h" #include "BLI_uuid.h" #include <cstdio> @@ -85,19 +86,19 @@ bool BLI_uuid_equal(const bUUID uuid1, const bUUID uuid2) void BLI_uuid_format(char *buffer, const bUUID uuid) { - std::sprintf(buffer, - "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", - uuid.time_low, - uuid.time_mid, - uuid.time_hi_and_version, - uuid.clock_seq_hi_and_reserved, - uuid.clock_seq_low, - uuid.node[0], - uuid.node[1], - uuid.node[2], - uuid.node[3], - uuid.node[4], - uuid.node[5]); + BLI_sprintf(buffer, + "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", + uuid.time_low, + uuid.time_mid, + uuid.time_hi_and_version, + uuid.clock_seq_hi_and_reserved, + uuid.clock_seq_low, + uuid.node[0], + uuid.node[1], + uuid.node[2], + uuid.node[3], + uuid.node[4], + uuid.node[5]); } bool BLI_uuid_parse_string(bUUID *uuid, const char *buffer) diff --git a/source/blender/blenlib/intern/winstuff.c b/source/blender/blenlib/intern/winstuff.c index 7e2c5e8f1dd..3a574b60ae2 100644 --- a/source/blender/blenlib/intern/winstuff.c +++ b/source/blender/blenlib/intern/winstuff.c @@ -110,7 +110,7 @@ bool BLI_windows_register_blend_extension(const bool background) &hkey, &dwd); if (lresult == ERROR_SUCCESS) { - sprintf(buffer, "\"%s\" \"%%1\"", BlPath); + BLI_snprintf(buffer, sizeof(buffer), "\"%s\" \"%%1\"", BlPath); lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE *)buffer, strlen(buffer) + 1); RegCloseKey(hkey); } @@ -129,7 +129,7 @@ bool BLI_windows_register_blend_extension(const bool background) &hkey, &dwd); if (lresult == ERROR_SUCCESS) { - sprintf(buffer, "\"%s\", 1", BlPath); + BLI_snprintf(buffer, sizeof(buffer), "\"%s\", 1", BlPath); lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE *)buffer, strlen(buffer) + 1); RegCloseKey(hkey); } @@ -167,10 +167,12 @@ bool BLI_windows_register_blend_extension(const bool background) RegCloseKey(root); printf("success (%s)\n", usr_mode ? "user" : "system"); if (!background) { - sprintf(MBox, - "File extension registered for %s.", - usr_mode ? "the current user. To register for all users, run as an administrator" : - "all users"); + BLI_snprintf(MBox, + sizeof(MBox), + "File extension registered for %s.", + usr_mode ? + "the current user. To register for all users, run as an administrator" : + "all users"); MessageBox(0, MBox, "Blender", MB_OK | MB_ICONINFORMATION); } return true; diff --git a/source/blender/blenloader/intern/writefile.cc b/source/blender/blenloader/intern/writefile.cc index 42bc884098e..6e48b65eb25 100644 --- a/source/blender/blenloader/intern/writefile.cc +++ b/source/blender/blenloader/intern/writefile.cc @@ -1048,7 +1048,7 @@ static void write_global(WriteData *wd, int fileflags, Main *mainvar) if (fileflags & G_FILE_RECOVER_WRITE) { STRNCPY(fg.filepath, mainvar->filepath); } - sprintf(subvstr, "%4d", BLENDER_FILE_SUBVERSION); + BLI_snprintf(subvstr, sizeof(subvstr), "%4d", BLENDER_FILE_SUBVERSION); memcpy(fg.subvstr, subvstr, 4); fg.subversion = BLENDER_FILE_SUBVERSION; @@ -1102,11 +1102,12 @@ static bool write_file_handle(Main *mainvar, wd = mywrite_begin(ww, compare, current); BlendWriter writer = {wd}; - sprintf(buf, - "BLENDER%c%c%.3d", - (sizeof(void *) == 8) ? '-' : '_', - (ENDIAN_ORDER == B_ENDIAN) ? 'V' : 'v', - BLENDER_FILE_VERSION); + BLI_snprintf(buf, + sizeof(buf), + "BLENDER%c%c%.3d", + (sizeof(void *) == 8) ? '-' : '_', + (ENDIAN_ORDER == B_ENDIAN) ? 'V' : 'v', + BLENDER_FILE_VERSION); mywrite(wd, buf, 12); diff --git a/source/blender/compositor/intern/COM_Debug.cc b/source/blender/compositor/intern/COM_Debug.cc index d184e5540ea..a670af5eaca 100644 --- a/source/blender/compositor/intern/COM_Debug.cc +++ b/source/blender/compositor/intern/COM_Debug.cc @@ -305,7 +305,7 @@ bool DebugInfo::graphviz_system(const ExecutionSystem *system, char *str, int ma for (NodeOperation *operation : group->operations_) { - sprintf(strbuf, "_%p", group); + BLI_snprintf(strbuf, sizeof(strbuf), "_%p", group); op_groups[operation].push_back(std::string(strbuf)); len += graphviz_operation( diff --git a/source/blender/draw/intern/draw_manager_profiling.c b/source/blender/draw/intern/draw_manager_profiling.c index d14f5c7f125..92cb3e008b9 100644 --- a/source/blender/draw/intern/draw_manager_profiling.c +++ b/source/blender/draw/intern/draw_manager_profiling.c @@ -225,15 +225,15 @@ void DRW_stats_draw(const rcti *rect) /* ------------------------------------------ */ /* Label row */ char col_label[32]; - sprintf(col_label, "Engine"); + BLI_snprintf(col_label, sizeof(col_label), "Engine"); draw_stat_5row(rect, u++, v, col_label, sizeof(col_label)); - sprintf(col_label, "Init"); + BLI_snprintf(col_label, sizeof(col_label), "Init"); draw_stat_5row(rect, u++, v, col_label, sizeof(col_label)); - sprintf(col_label, "Background"); + BLI_snprintf(col_label, sizeof(col_label), "Background"); draw_stat_5row(rect, u++, v, col_label, sizeof(col_label)); - sprintf(col_label, "Render"); + BLI_snprintf(col_label, sizeof(col_label), "Render"); draw_stat_5row(rect, u++, v, col_label, sizeof(col_label)); - sprintf(col_label, "Total (w/o cache)"); + BLI_snprintf(col_label, sizeof(col_label), "Total (w/o cache)"); draw_stat_5row(rect, u++, v, col_label, sizeof(col_label)); v++; @@ -245,42 +245,45 @@ void DRW_stats_draw(const rcti *rect) draw_stat_5row(rect, u++, v, engine->idname, sizeof(engine->idname)); init_tot_time += data->init_time; - sprintf(time_to_txt, "%.2fms", data->init_time); + BLI_snprintf(time_to_txt, sizeof(time_to_txt), "%.2fms", data->init_time); draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt)); background_tot_time += data->background_time; - sprintf(time_to_txt, "%.2fms", data->background_time); + BLI_snprintf(time_to_txt, sizeof(time_to_txt), "%.2fms", data->background_time); draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt)); render_tot_time += data->render_time; - sprintf(time_to_txt, "%.2fms", data->render_time); + BLI_snprintf(time_to_txt, sizeof(time_to_txt), "%.2fms", data->render_time); draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt)); tot_time += data->init_time + data->background_time + data->render_time; - sprintf(time_to_txt, "%.2fms", data->init_time + data->background_time + data->render_time); + BLI_snprintf(time_to_txt, + sizeof(time_to_txt), + "%.2fms", + data->init_time + data->background_time + data->render_time); draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt)); v++; } /* Totals row */ u = 0; - sprintf(col_label, "Sub Total"); + BLI_snprintf(col_label, sizeof(col_label), "Sub Total"); draw_stat_5row(rect, u++, v, col_label, sizeof(col_label)); - sprintf(time_to_txt, "%.2fms", init_tot_time); + BLI_snprintf(time_to_txt, sizeof(time_to_txt), "%.2fms", init_tot_time); draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt)); - sprintf(time_to_txt, "%.2fms", background_tot_time); + BLI_snprintf(time_to_txt, sizeof(time_to_txt), "%.2fms", background_tot_time); draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt)); - sprintf(time_to_txt, "%.2fms", render_tot_time); + BLI_snprintf(time_to_txt, sizeof(time_to_txt), "%.2fms", render_tot_time); draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt)); - sprintf(time_to_txt, "%.2fms", tot_time); + BLI_snprintf(time_to_txt, sizeof(time_to_txt), "%.2fms", tot_time); draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt)); v += 2; u = 0; double *cache_time = DRW_view_data_cache_time_get(DST.view_data_active); - sprintf(col_label, "Cache Time"); + BLI_snprintf(col_label, sizeof(col_label), "Cache Time"); draw_stat_5row(rect, u++, v, col_label, sizeof(col_label)); - sprintf(time_to_txt, "%.2fms", *cache_time); + BLI_snprintf(time_to_txt, sizeof(time_to_txt), "%.2fms", *cache_time); draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt)); v += 2; @@ -292,17 +295,18 @@ void DRW_stats_draw(const rcti *rect) uint tex_mem = GPU_texture_memory_usage_get(); uint vbo_mem = GPU_vertbuf_get_memory_usage(); - sprintf(stat_string, "GPU Memory"); + BLI_snprintf(stat_string, sizeof(stat_string), "GPU Memory"); draw_stat(rect, 0, v, stat_string, sizeof(stat_string)); - sprintf(stat_string, "%.2fMB", (double)(tex_mem + vbo_mem) / 1000000.0); + BLI_snprintf( + stat_string, sizeof(stat_string), "%.2fMB", (double)(tex_mem + vbo_mem) / 1000000.0); draw_stat_5row(rect, 1, v++, stat_string, sizeof(stat_string)); - sprintf(stat_string, "Textures"); + BLI_snprintf(stat_string, sizeof(stat_string), "Textures"); draw_stat(rect, 1, v, stat_string, sizeof(stat_string)); - sprintf(stat_string, "%.2fMB", (double)tex_mem / 1000000.0); + BLI_snprintf(stat_string, sizeof(stat_string), "%.2fMB", (double)tex_mem / 1000000.0); draw_stat_5row(rect, 1, v++, stat_string, sizeof(stat_string)); - sprintf(stat_string, "Meshes"); + BLI_snprintf(stat_string, sizeof(stat_string), "Meshes"); draw_stat(rect, 1, v, stat_string, sizeof(stat_string)); - sprintf(stat_string, "%.2fMB", (double)vbo_mem / 1000000.0); + BLI_snprintf(stat_string, sizeof(stat_string), "%.2fMB", (double)vbo_mem / 1000000.0); draw_stat_5row(rect, 1, v++, stat_string, sizeof(stat_string)); v += 1; diff --git a/source/blender/draw/intern/draw_pbvh.cc b/source/blender/draw/intern/draw_pbvh.cc index b25bb42a8a5..6c504e63511 100644 --- a/source/blender/draw/intern/draw_pbvh.cc +++ b/source/blender/draw/intern/draw_pbvh.cc @@ -86,7 +86,7 @@ struct PBVHVbo { { char buf[512]; - sprintf(buf, "%d:%d:%s", int(type), int(domain), name.c_str()); + BLI_snprintf(buf, sizeof(buf), "%d:%d:%s", int(type), int(domain), name.c_str()); key = string(buf); return key; diff --git a/source/blender/editors/io/io_collada.c b/source/blender/editors/io/io_collada.c index a630f150e0e..7bc28a0ba89 100644 --- a/source/blender/editors/io/io_collada.c +++ b/source/blender/editors/io/io_collada.c @@ -219,7 +219,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op) } char buff[100]; - sprintf(buff, "Exported %d Objects", export_count); + BLI_snprintf(buff, sizeof(buff), "Exported %d Objects", export_count); BKE_report(op->reports, RPT_INFO, buff); return OPERATOR_FINISHED; } diff --git a/source/blender/editors/object/object_bake_api.c b/source/blender/editors/object/object_bake_api.c index d05badc8fee..b8e5c4e5522 100644 --- a/source/blender/editors/object/object_bake_api.c +++ b/source/blender/editors/object/object_bake_api.c @@ -893,7 +893,7 @@ static bool bake_targets_output_external(const BakeAPIRender *bkr, else { /* if everything else fails, use the material index */ char tmp[5]; - sprintf(tmp, "%d", i % 1000); + BLI_snprintf(tmp, sizeof(tmp), "%d", i % 1000); BLI_path_suffix(name, FILE_MAX, tmp, "_"); } } diff --git a/source/blender/editors/object/object_constraint.c b/source/blender/editors/object/object_constraint.c index 1386da5dbde..cbed01442ee 100644 --- a/source/blender/editors/object/object_constraint.c +++ b/source/blender/editors/object/object_constraint.c @@ -182,7 +182,7 @@ static char *buildmenu_pyconstraints(Main *bmain, Text *con_text, int *pyconinde int i; /* add title first */ - sprintf(buf, "Scripts: %%t|[None]%%x0|"); + BLI_snprintf(buf, sizeof(buf), "Scripts: %%t|[None]%%x0|"); BLI_dynstr_append(pupds, buf); /* init active-index first */ @@ -201,7 +201,7 @@ static char *buildmenu_pyconstraints(Main *bmain, Text *con_text, int *pyconinde if (BPY_is_pyconstraint(text)) { BLI_dynstr_append(pupds, text->id.name + 2); - sprintf(buf, "%%x%d", i); + BLI_snprintf(buf, sizeof(buf), "%%x%d", i); BLI_dynstr_append(pupds, buf); if (text->id.next) { diff --git a/source/blender/editors/render/render_internal.cc b/source/blender/editors/render/render_internal.cc index e66cabbc9f8..41f1497cac2 100644 --- a/source/blender/editors/render/render_internal.cc +++ b/source/blender/editors/render/render_internal.cc @@ -405,56 +405,57 @@ static void make_renderinfo_string(const RenderStats *rs, /* local view */ if (rs->localview) { - spos += sprintf(spos, "%s | ", TIP_("3D Local View")); + spos += BLI_sprintf(spos, "%s | ", TIP_("3D Local View")); } else if (v3d_override) { - spos += sprintf(spos, "%s | ", TIP_("3D View")); + spos += BLI_sprintf(spos, "%s | ", TIP_("3D View")); } /* frame number */ - spos += sprintf(spos, TIP_("Frame:%d "), (scene->r.cfra)); + spos += BLI_sprintf(spos, TIP_("Frame:%d "), (scene->r.cfra)); /* previous and elapsed time */ BLI_timecode_string_from_time_simple(info_time_str, sizeof(info_time_str), rs->lastframetime); if (rs->infostr && rs->infostr[0]) { if (rs->lastframetime != 0.0) { - spos += sprintf(spos, TIP_("| Last:%s "), info_time_str); + spos += BLI_sprintf(spos, TIP_("| Last:%s "), info_time_str); } else { - spos += sprintf(spos, "| "); + spos += BLI_sprintf(spos, "| "); } BLI_timecode_string_from_time_simple( info_time_str, sizeof(info_time_str), PIL_check_seconds_timer() - rs->starttime); } else { - spos += sprintf(spos, "| "); + spos += BLI_sprintf(spos, "| "); } - spos += sprintf(spos, TIP_("Time:%s "), info_time_str); + spos += BLI_sprintf(spos, TIP_("Time:%s "), info_time_str); /* statistics */ if (rs->statstr) { if (rs->statstr[0]) { - spos += sprintf(spos, "| %s ", rs->statstr); + spos += BLI_sprintf(spos, "| %s ", rs->statstr); } } else { if (rs->mem_peak == 0.0f) { - spos += sprintf(spos, TIP_("| Mem:%.2fM (Peak %.2fM) "), megs_used_memory, megs_peak_memory); + spos += BLI_sprintf( + spos, TIP_("| Mem:%.2fM (Peak %.2fM) "), megs_used_memory, megs_peak_memory); } else { - spos += sprintf(spos, TIP_("| Mem:%.2fM, Peak: %.2fM "), rs->mem_used, rs->mem_peak); + spos += BLI_sprintf(spos, TIP_("| Mem:%.2fM, Peak: %.2fM "), rs->mem_used, rs->mem_peak); } } /* extra info */ if (rs->infostr && rs->infostr[0]) { - spos += sprintf(spos, "| %s ", rs->infostr); + spos += BLI_sprintf(spos, "| %s ", rs->infostr); } else if (error && error[0]) { - spos += sprintf(spos, "| %s ", error); + spos += BLI_sprintf(spos, "| %s ", error); } /* very weak... but 512 characters is quite safe */ diff --git a/source/blender/editors/render/render_preview.cc b/source/blender/editors/render/render_preview.cc index 5aae48b1138..5bfa038b4f4 100644 --- a/source/blender/editors/render/render_preview.cc +++ b/source/blender/editors/render/render_preview.cc @@ -630,10 +630,10 @@ static bool ed_preview_draw_rect(ScrArea *area, int split, int first, rcti *rect bool ok = false; if (!split || first) { - sprintf(name, "Preview %p", (void *)area); + BLI_snprintf(name, sizeof(name), "Preview %p", (void *)area); } else { - sprintf(name, "SecondPreview %p", (void *)area); + BLI_snprintf(name, sizeof(name), "SecondPreview %p", (void *)area); } if (split) { @@ -1152,10 +1152,10 @@ static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int firs } if (!split || first) { - sprintf(name, "Preview %p", sp->owner); + BLI_snprintf(name, sizeof(name), "Preview %p", sp->owner); } else { - sprintf(name, "SecondPreview %p", sp->owner); + BLI_snprintf(name, sizeof(name), "SecondPreview %p", sp->owner); } re = RE_GetRender(name); diff --git a/source/blender/editors/space_node/space_node.cc b/source/blender/editors/space_node/space_node.cc index 5754e77399f..ce0273eec81 100644 --- a/source/blender/editors/space_node/space_node.cc +++ b/source/blender/editors/space_node/space_node.cc @@ -181,7 +181,7 @@ void ED_node_tree_path_get(SpaceNode *snode, char *value) value += strlen(path->display_name); } else { - sprintf(value, "/%s", path->display_name); + BLI_sprintf(value, "/%s", path->display_name); value += strlen(path->display_name) + 1; } } diff --git a/source/blender/editors/space_outliner/tree/tree_element_rna.cc b/source/blender/editors/space_outliner/tree/tree_element_rna.cc index 6e92fa087fb..275b4391d24 100644 --- a/source/blender/editors/space_outliner/tree/tree_element_rna.cc +++ b/source/blender/editors/space_outliner/tree/tree_element_rna.cc @@ -232,12 +232,13 @@ TreeElementRNAArrayElement::TreeElementRNAArrayElement(TreeElement &legacy_te, char c = RNA_property_array_item_char(TreeElementRNAArrayElement::getPropertyRNA(), index); - legacy_te_.name = static_cast<char *>(MEM_callocN(sizeof(char[20]), "OutlinerRNAArrayName")); + const size_t name_size = sizeof(char[20]); + legacy_te_.name = static_cast<char *>(MEM_callocN(name_size, "OutlinerRNAArrayName")); if (c) { - sprintf((char *)legacy_te_.name, " %c", c); + BLI_snprintf((char *)legacy_te_.name, name_size, " %c", c); } else { - sprintf((char *)legacy_te_.name, " %d", index + 1); + BLI_snprintf((char *)legacy_te_.name, name_size, " %d", index + 1); } legacy_te_.flag |= TE_FREE_NAME; } diff --git a/source/blender/editors/space_view3d/view3d_draw.cc b/source/blender/editors/space_view3d/view3d_draw.cc index 31b26ba4cda..5d4ed032bb4 100644 --- a/source/blender/editors/space_view3d/view3d_draw.cc +++ b/source/blender/editors/space_view3d/view3d_draw.cc @@ -1306,15 +1306,15 @@ static void draw_selected_name( char info[300]; char *s = info; - s += sprintf(s, "(%d)", cfra); + s += BLI_sprintf(s, "(%d)", cfra); if ((ob == nullptr) || (ob->mode == OB_MODE_OBJECT)) { BKE_view_layer_synced_ensure(scene, view_layer); LayerCollection *layer_collection = BKE_view_layer_active_collection_get(view_layer); - s += sprintf(s, - " %s%s", - BKE_collection_ui_name_get(layer_collection->collection), - (ob == nullptr) ? "" : " |"); + s += BLI_sprintf(s, + " %s%s", + BKE_collection_ui_name_get(layer_collection->collection), + (ob == nullptr) ? "" : " |"); } /* Info can contain: @@ -1407,12 +1407,12 @@ static void draw_selected_name( } if (markern) { - s += sprintf(s, " <%s>", markern); + s += BLI_sprintf(s, " <%s>", markern); } if (v3d->flag2 & V3D_SHOW_VIEWER) { if (!BLI_listbase_is_empty(&v3d->viewer_path.path)) { - s += sprintf(s, "%s", IFACE_(" (Viewer)")); + s += BLI_sprintf(s, "%s", IFACE_(" (Viewer)")); } } diff --git a/source/blender/io/avi/intern/avi_codecs.c b/source/blender/io/avi/intern/avi_codecs.c index cbb96e12930..ba897ef808a 100644 --- a/source/blender/io/avi/intern/avi_codecs.c +++ b/source/blender/io/avi/intern/avi_codecs.c @@ -14,6 +14,8 @@ #include "avi_rgb.h" #include "avi_rgb32.h" +#include "BLI_string.h" + void *avi_format_convert( AviMovie *movie, int stream, void *buffer, AviFormat from, AviFormat to, size_t *size) { @@ -68,10 +70,10 @@ int avi_get_data_id(AviFormat format, int stream) char fcc[5]; if (avi_get_format_type(format) == FCC("vids")) { - sprintf(fcc, "%2.2ddc", stream); + BLI_snprintf(fcc, sizeof(fcc), "%2.2ddc", stream); } else if (avi_get_format_type(format) == FCC("auds")) { - sprintf(fcc, "%2.2ddc", stream); + BLI_snprintf(fcc, sizeof(fcc), "%2.2ddc", stream); } else { return 0; diff --git a/source/blender/io/collada/AnimationExporter.cpp b/source/blender/io/collada/AnimationExporter.cpp index 85e8ccf9f2a..24d2072f840 100644 --- a/source/blender/io/collada/AnimationExporter.cpp +++ b/source/blender/io/collada/AnimationExporter.cpp @@ -43,7 +43,8 @@ bool AnimationExporter::open_animation_container(bool has_container, Object *ob) { if (!has_container) { char anim_id[200]; - sprintf(anim_id, "action_container-%s", translate_id(id_name(ob)).c_str()); + BLI_snprintf( + anim_id, sizeof(anim_id), "action_container-%s", translate_id(id_name(ob)).c_str()); openAnimation(anim_id, encode_xml(id_name(ob))); } return true; diff --git a/source/blender/io/collada/GeometryExporter.cpp b/source/blender/io/collada/GeometryExporter.cpp index a069c32026b..f6f9026481c 100644 --- a/source/blender/io/collada/GeometryExporter.cpp +++ b/source/blender/io/collada/GeometryExporter.cpp @@ -522,7 +522,7 @@ std::string GeometryExporter::makeTexcoordSourceId(std::string &geom_id, suffix[0] = '\0'; } else { - sprintf(suffix, "-%d", layer_index); + BLI_snprintf(suffix, sizeof(suffix), "-%d", layer_index); } return getIdBySemantics(geom_id, COLLADASW::InputSemantic::TEXCOORD) + suffix; } diff --git a/source/blender/io/gpencil/intern/gpencil_io_export_svg.cc b/source/blender/io/gpencil/intern/gpencil_io_export_svg.cc index 8acb87f8e58..b85fd33e116 100644 --- a/source/blender/io/gpencil/intern/gpencil_io_export_svg.cc +++ b/source/blender/io/gpencil/intern/gpencil_io_export_svg.cc @@ -90,7 +90,8 @@ void GpencilExporterSVG::create_document_header() pugi::xml_node comment = main_doc_.append_child(pugi::node_comment); char txt[128]; - sprintf(txt, " Generator: Blender, %s - %s ", SVG_EXPORTER_NAME, SVG_EXPORTER_VERSION); + BLI_snprintf( + txt, sizeof(txt), " Generator: Blender, %s - %s ", SVG_EXPORTER_NAME, SVG_EXPORTER_VERSION); comment.set_value(txt); pugi::xml_node doctype = main_doc_.append_child(pugi::node_doctype); @@ -147,7 +148,7 @@ void GpencilExporterSVG::export_gpencil_layers() pugi::xml_node ob_node = frame_node_.append_child("g"); char obtxt[96]; - sprintf(obtxt, "blender_object_%s", ob->id.name + 2); + BLI_snprintf(obtxt, sizeof(obtxt), "blender_object_%s", ob->id.name + 2); ob_node.append_attribute("id").set_value(obtxt); /* Use evaluated version to get strokes with modifiers. */ @@ -402,7 +403,7 @@ std::string GpencilExporterSVG::rgb_to_hexstr(const float color[3]) uint8_t g = color[1] * 255.0f; uint8_t b = color[2] * 255.0f; char hex_string[20]; - sprintf(hex_string, "#%02X%02X%02X", r, g, b); + BLI_snprintf(hex_string, sizeof(hex_string), "#%02X%02X%02X", r, g, b); std::string hexstr = hex_string; diff --git a/source/blender/makesrna/intern/rna_particle.c b/source/blender/makesrna/intern/rna_particle.c index 02105c7b425..a56e7d28ef7 100644 --- a/source/blender/makesrna/intern/rna_particle.c +++ b/source/blender/makesrna/intern/rna_particle.c @@ -1188,7 +1188,7 @@ static void rna_ParticleTarget_name_get(PointerRNA *ptr, char *str) if (psys) { if (pt->ob) { - sprintf(str, "%s: %s", pt->ob->id.name + 2, psys->name); + BLI_sprintf(str, "%s: %s", pt->ob->id.name + 2, psys->name); } else { strcpy(str, psys->name); @@ -1315,7 +1315,7 @@ static void rna_ParticleDupliWeight_name_get(PointerRNA *ptr, char *str) ParticleDupliWeight *dw = ptr->data; if (dw->ob) { - sprintf(str, "%s: %i", dw->ob->id.name + 2, dw->count); + BLI_sprintf(str, "%s: %i", dw->ob->id.name + 2, dw->count); } else { strcpy(str, "No object"); diff --git a/source/blender/nodes/texture/nodes/node_texture_output.c b/source/blender/nodes/texture/nodes/node_texture_output.c index b300ba9ef77..89dd8e8d8bd 100644 --- a/source/blender/nodes/texture/nodes/node_texture_output.c +++ b/source/blender/nodes/texture/nodes/node_texture_output.c @@ -83,7 +83,7 @@ static void unique_name(bNode *node) BLI_strncpy(new_name, name, sizeof(tno->name)); name = new_name; } - sprintf(new_name + new_len - 4, ".%03d", ++suffix); + BLI_sprintf(new_name + new_len - 4, ".%03d", ++suffix); } if (new_name[0] != '\0') { diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index 5c9c83f2e6e..1aa20700f31 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -7,6 +7,7 @@ #include "BLI_math.h" #include "BLI_sort.h" +#include "BLI_string.h" #include "DNA_material_types.h" #include "DNA_mesh_types.h" @@ -4247,16 +4248,16 @@ char *BPy_BMElem_StringFromHType_ex(const char htype, char ret[32]) /* zero to ensure string is always NULL terminated */ char *ret_ptr = ret; if (htype & BM_VERT) { - ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMVert_Type.tp_name); + ret_ptr += BLI_sprintf(ret_ptr, "/%s", BPy_BMVert_Type.tp_name); } if (htype & BM_EDGE) { - ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMEdge_Type.tp_name); + ret_ptr += BLI_sprintf(ret_ptr, "/%s", BPy_BMEdge_Type.tp_name); } if (htype & BM_FACE) { - ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMFace_Type.tp_name); + ret_ptr += BLI_sprintf(ret_ptr, "/%s", BPy_BMFace_Type.tp_name); } if (htype & BM_LOOP) { - ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMLoop_Type.tp_name); + ret_ptr += BLI_sprintf(ret_ptr, "/%s", BPy_BMLoop_Type.tp_name); } ret[0] = '('; *ret_ptr++ = ')'; diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index e6525db62a4..3ceed4ab207 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -993,7 +993,7 @@ static PyObject *pyrna_prop_str(BPy_PropertyRNA *self) } if (len != -1) { - sprintf(--c, "[%d]", len); + BLI_sprintf(--c, "[%d]", len); } /* If a pointer, try to print name of pointer target too. */ diff --git a/source/blender/sequencer/intern/disk_cache.c b/source/blender/sequencer/intern/disk_cache.c index 596a28201cc..beb2c77b003 100644 --- a/source/blender/sequencer/intern/disk_cache.c +++ b/source/blender/sequencer/intern/disk_cache.c @@ -303,7 +303,8 @@ static void seq_disk_cache_get_dir( char project_dir[FILE_MAX]; seq_disk_cache_get_project_dir(disk_cache, project_dir, sizeof(project_dir)); - sprintf(scene_name, "%s-%" PRId64, scene->id.name, disk_cache->timestamp); + BLI_snprintf( + scene_name, sizeof(scene_name), "%s-%" PRId64, scene->id.name, disk_cache->timestamp); BLI_strncpy(seq_name, seq->name, sizeof(seq_name)); BLI_filename_make_safe(scene_name); BLI_filename_make_safe(seq_name); @@ -319,14 +320,15 @@ static void seq_disk_cache_get_file_path(SeqDiskCache *disk_cache, seq_disk_cache_get_dir(disk_cache, key->context.scene, key->seq, path, path_len); int frameno = (int)key->frame_index / DCACHE_IMAGES_PER_FILE; char cache_filename[FILE_MAXFILE]; - sprintf(cache_filename, - DCACHE_FNAME_FORMAT, - key->type, - key->context.rectx, - key->context.recty, - key->context.preview_render_size, - key->context.view_id, - frameno); + BLI_snprintf(cache_filename, + sizeof(cache_filename), + DCACHE_FNAME_FORMAT, + key->type, + key->context.rectx, + key->context.recty, + key->context.preview_render_size, + key->context.view_id, + frameno); BLI_path_append(path, path_len, cache_filename); } |