1
1

Cleanup: replace strncpy with BLI_strncpy

Also replace strncpy+strcat with BLI_string_join
This commit is contained in:
2022-09-10 16:51:15 +10:00
parent 489cb7fd7e
commit 8cb3b49e51
25 changed files with 36 additions and 36 deletions

View File

@@ -154,12 +154,12 @@ void BLI_hostname_get(char *buffer, size_t bufsize)
if (gethostname(buffer, bufsize - 1) < 0) {
BLI_strncpy(buffer, "-unknown-", bufsize);
}
/* When gethostname() truncates, it doesn't guarantee the trailing \0. */
/* When `gethostname()` truncates, it doesn't guarantee the trailing `\0`. */
buffer[bufsize - 1] = '\0';
#else
DWORD bufsize_inout = bufsize;
if (!GetComputerName(buffer, &bufsize_inout)) {
strncpy(buffer, "-unknown-", bufsize);
BLI_strncpy(buffer, "-unknown-", bufsize);
}
#endif
}

View File

@@ -16,6 +16,7 @@
#include "BLI_linklist_stack.h"
#include "BLI_math.h"
#include "BLI_rand.h"
#include "BLI_string_utils.h"
#include "BLI_utildefines.h"
#include "BKE_context.h"
@@ -2687,12 +2688,13 @@ static void ed_panel_draw(const bContext *C,
const uiStyle *style = UI_style_get_dpi();
/* Draw panel. */
char block_name[BKE_ST_MAXNAME + INSTANCED_PANEL_UNIQUE_STR_LEN];
strncpy(block_name, pt->idname, BKE_ST_MAXNAME);
if (unique_panel_str != NULL) {
if (unique_panel_str) {
/* Instanced panels should have already been added at this point. */
strncat(block_name, unique_panel_str, INSTANCED_PANEL_UNIQUE_STR_LEN);
BLI_string_join(block_name, sizeof(block_name), pt->idname, unique_panel_str);
}
else {
STRNCPY(block_name, pt->idname);
}
uiBlock *block = UI_block_begin(C, region, block_name, UI_EMBOSS);

View File

@@ -840,7 +840,7 @@ void ED_spacetype_action(void)
ARegionType *art;
st->spaceid = SPACE_ACTION;
strncpy(st->name, "Action", BKE_ST_MAXNAME);
STRNCPY(st->name, "Action");
st->create = action_create;
st->free = action_free;

View File

@@ -917,7 +917,7 @@ void ED_spacetype_buttons(void)
ARegionType *art;
st->spaceid = SPACE_PROPERTIES;
strncpy(st->name, "Buttons", BKE_ST_MAXNAME);
STRNCPY(st->name, "Buttons");
st->create = buttons_create;
st->free = buttons_free;

View File

@@ -1251,7 +1251,7 @@ void ED_spacetype_clip(void)
ARegionType *art;
st->spaceid = SPACE_CLIP;
strncpy(st->name, "Clip", BKE_ST_MAXNAME);
STRNCPY(st->name, "Clip");
st->create = clip_create;
st->free = clip_free;

View File

@@ -289,7 +289,7 @@ void ED_spacetype_console(void)
ARegionType *art;
st->spaceid = SPACE_CONSOLE;
strncpy(st->name, "Console", BKE_ST_MAXNAME);
STRNCPY(st->name, "Console");
st->create = console_create;
st->free = console_free;

View File

@@ -992,7 +992,7 @@ void ED_spacetype_file(void)
ARegionType *art;
st->spaceid = SPACE_FILE;
strncpy(st->name, "File", BKE_ST_MAXNAME);
STRNCPY(st->name, "File");
st->create = file_create;
st->free = file_free;

View File

@@ -810,7 +810,7 @@ void ED_spacetype_ipo(void)
ARegionType *art;
st->spaceid = SPACE_GRAPH;
strncpy(st->name, "Graph", BKE_ST_MAXNAME);
STRNCPY(st->name, "Graph");
st->create = graph_create;
st->free = graph_free;

View File

@@ -1029,7 +1029,7 @@ void ED_spacetype_image(void)
ARegionType *art;
st->spaceid = SPACE_IMAGE;
strncpy(st->name, "Image", BKE_ST_MAXNAME);
STRNCPY(st->name, "Image");
st->create = image_create;
st->free = image_free;

View File

@@ -254,7 +254,7 @@ void ED_spacetype_info(void)
ARegionType *art;
st->spaceid = SPACE_INFO;
strncpy(st->name, "Info", BKE_ST_MAXNAME);
STRNCPY(st->name, "Info");
st->create = info_create;
st->free = info_free;

View File

@@ -568,7 +568,7 @@ void ED_spacetype_nla(void)
ARegionType *art;
st->spaceid = SPACE_NLA;
strncpy(st->name, "NLA", BKE_ST_MAXNAME);
STRNCPY(st->name, "NLA");
st->create = nla_create;
st->free = nla_free;

View File

@@ -1021,7 +1021,7 @@ void ED_spacetype_node()
ARegionType *art;
st->spaceid = SPACE_NODE;
strncpy(st->name, "Node", BKE_ST_MAXNAME);
STRNCPY(st->name, "Node");
st->create = node_create;
st->free = node_free;

View File

@@ -445,7 +445,7 @@ void ED_spacetype_outliner(void)
ARegionType *art;
st->spaceid = SPACE_OUTLINER;
strncpy(st->name, "Outliner", BKE_ST_MAXNAME);
STRNCPY(st->name, "Outliner");
st->create = outliner_create;
st->free = outliner_free;

View File

@@ -152,7 +152,7 @@ void ED_spacetype_script(void)
ARegionType *art;
st->spaceid = SPACE_SCRIPT;
strncpy(st->name, "Script", BKE_ST_MAXNAME);
STRNCPY(st->name, "Script");
st->create = script_create;
st->free = script_free;

View File

@@ -997,7 +997,7 @@ void ED_spacetype_sequencer(void)
ARegionType *art;
st->spaceid = SPACE_SEQ;
strncpy(st->name, "Sequencer", BKE_ST_MAXNAME);
STRNCPY(st->name, "Sequencer");
st->create = sequencer_create;
st->free = sequencer_free;

View File

@@ -619,7 +619,7 @@ void ED_spacetype_spreadsheet()
ARegionType *art;
st->spaceid = SPACE_SPREADSHEET;
strncpy(st->name, "Spreadsheet", BKE_ST_MAXNAME);
STRNCPY(st->name, "Spreadsheet");
st->create = spreadsheet_create;
st->free = spreadsheet_free;

View File

@@ -136,7 +136,7 @@ void ED_spacetype_statusbar(void)
ARegionType *art;
st->spaceid = SPACE_STATUSBAR;
strncpy(st->name, "Status Bar", BKE_ST_MAXNAME);
STRNCPY(st->name, "Status Bar");
st->create = statusbar_create;
st->free = statusbar_free;

View File

@@ -403,7 +403,7 @@ void ED_spacetype_text(void)
ARegionType *art;
st->spaceid = SPACE_TEXT;
strncpy(st->name, "Text", BKE_ST_MAXNAME);
STRNCPY(st->name, "Text");
st->create = text_create;
st->free = text_free;

View File

@@ -706,7 +706,7 @@ static void text_update_drawcache(SpaceText *st, ARegion *region)
drawcache->showlinenrs = st->showlinenrs;
drawcache->tabnumber = st->tabnumber;
strncpy(drawcache->text_id, txt->id.name, MAX_ID_NAME);
STRNCPY(drawcache->text_id, txt->id.name);
/* clear update flag */
drawcache->update_flag = 0;

View File

@@ -288,7 +288,7 @@ void ED_spacetype_topbar(void)
ARegionType *art;
st->spaceid = SPACE_TOPBAR;
strncpy(st->name, "Top Bar", BKE_ST_MAXNAME);
STRNCPY(st->name, "Top Bar");
st->create = topbar_create;
st->free = topbar_free;

View File

@@ -189,7 +189,7 @@ void ED_spacetype_userpref(void)
ARegionType *art;
st->spaceid = SPACE_USERPREF;
strncpy(st->name, "Userpref", BKE_ST_MAXNAME);
STRNCPY(st->name, "Userpref");
st->create = userpref_create;
st->free = userpref_free;

View File

@@ -1972,7 +1972,7 @@ void ED_spacetype_view3d(void)
ARegionType *art;
st->spaceid = SPACE_VIEW3D;
strncpy(st->name, "View3D", BKE_ST_MAXNAME);
STRNCPY(st->name, "View3D");
st->create = view3d_create;
st->free = view3d_free;

View File

@@ -18,6 +18,7 @@
#include <time.h>
#include "BLI_fileops.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "MEM_guardedalloc.h"
@@ -56,9 +57,8 @@ static void fillCineonMainHeader(LogImageFile *cineon,
cineon->height *
getRowLength(cineon->width, cineon->element[0]),
cineon->isMSB);
strcpy(header->fileHeader.version, "v4.5");
strncpy(header->fileHeader.file_name, filepath, 99);
header->fileHeader.file_name[99] = 0;
STRNCPY(header->fileHeader.version, "v4.5");
STRNCPY(header->fileHeader.file_name, filepath);
fileClock = time(NULL);
fileTime = localtime(&fileClock);
strftime(header->fileHeader.creation_date, 12, "%Y:%m:%d", fileTime);
@@ -93,8 +93,7 @@ static void fillCineonMainHeader(LogImageFile *cineon,
header->imageHeader.green_primary_y = swap_float(0.0f, cineon->isMSB);
header->imageHeader.blue_primary_x = swap_float(0.0f, cineon->isMSB);
header->imageHeader.blue_primary_y = swap_float(0.0f, cineon->isMSB);
strncpy(header->imageHeader.label, creator, 199);
header->imageHeader.label[199] = 0;
STRNCPY(header->imageHeader.label, creator);
header->imageHeader.interleave = 0;
header->imageHeader.data_sign = 0;
header->imageHeader.sense = 0;

View File

@@ -18,6 +18,7 @@
#include <time.h>
#include "BLI_fileops.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "MEM_guardedalloc.h"
@@ -60,14 +61,12 @@ static void fillDpxMainHeader(LogImageFile *dpx,
header->fileHeader.ind_hdr_size = swap_uint(sizeof(DpxFilmHeader) + sizeof(DpxTelevisionHeader),
dpx->isMSB);
header->fileHeader.user_data_size = DPX_UNDEFINED_U32;
strncpy(header->fileHeader.file_name, filename, 99);
header->fileHeader.file_name[99] = 0;
STRNCPY(header->fileHeader.file_name, filename);
fileClock = time(NULL);
fileTime = localtime(&fileClock);
strftime(header->fileHeader.creation_date, 24, "%Y:%m:%d:%H:%M:%S%Z", fileTime);
header->fileHeader.creation_date[23] = 0;
strncpy(header->fileHeader.creator, creator, 99);
header->fileHeader.creator[99] = 0;
STRNCPY(header->fileHeader.creator, creator);
header->fileHeader.project[0] = 0;
header->fileHeader.copyright[0] = 0;
header->fileHeader.key = 0xFFFFFFFF;

View File

@@ -51,7 +51,7 @@ static void initData(ModifierData *md)
VolumeToMeshModifierData *vmmd = reinterpret_cast<VolumeToMeshModifierData *>(md);
vmmd->object = nullptr;
vmmd->threshold = 0.1f;
strncpy(vmmd->grid_name, "density", MAX_NAME);
STRNCPY(vmmd->grid_name, "density");
vmmd->adaptivity = 0.0f;
vmmd->resolution_mode = VOLUME_TO_MESH_RESOLUTION_MODE_GRID;
vmmd->voxel_amount = 32;