From 58ba5a65bc512b75d876c40ef6e978359166f45a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 5 Apr 2018 18:39:23 +0200 Subject: Cleanup: use string macros to avoid duplicate args --- source/blender/blenkernel/intern/image.c | 121 ++++++++++++++++--------------- 1 file changed, 61 insertions(+), 60 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 6abffd83a4d..e8b5ce77613 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -152,7 +152,7 @@ static void imagecache_put(Image *image, int index, ImBuf *ibuf) if (image->cache == NULL) { // char cache_name[64]; - // BLI_snprintf(cache_name, sizeof(cache_name), "Image Datablock %s", image->id.name); + // SNPRINTF(cache_name, "Image Datablock %s", image->id.name); image->cache = IMB_moviecache_create("Image Datablock Cache", sizeof(ImageCacheKey), imagecache_hashhash, imagecache_hashcmp); @@ -437,7 +437,7 @@ static void copy_image_packedfiles(ListBase *lb_dst, const ListBase *lb_src) BLI_listbase_clear(lb_dst); for (imapf_src = lb_src->first; imapf_src; imapf_src = imapf_src->next) { ImagePackedFile *imapf_dst = MEM_mallocN(sizeof(ImagePackedFile), "Image Packed Files (copy)"); - BLI_strncpy(imapf_dst->filepath, imapf_src->filepath, sizeof(imapf_dst->filepath)); + STRNCPY(imapf_dst->filepath, imapf_src->filepath); if (imapf_src->packedfile) imapf_dst->packedfile = dupPackedFile(imapf_src->packedfile); @@ -593,7 +593,7 @@ Image *BKE_image_load(Main *bmain, const char *filepath) int file; char str[FILE_MAX]; - BLI_strncpy(str, filepath, sizeof(str)); + STRNCPY(str, filepath); BLI_path_abs(str, bmain->name); /* exists? */ @@ -603,7 +603,7 @@ Image *BKE_image_load(Main *bmain, const char *filepath) close(file); ima = image_alloc(bmain, BLI_path_basename(filepath), IMA_SRC_FILE, IMA_TYPE_IMAGE); - BLI_strncpy(ima->name, filepath, sizeof(ima->name)); + STRNCPY(ima->name, filepath); if (BLI_testextensie_array(filepath, imb_ext_movie)) ima->source = IMA_SRC_MOVIE; @@ -622,13 +622,13 @@ Image *BKE_image_load_exists_ex(const char *filepath, bool *r_exists) Image *ima; char str[FILE_MAX], strtest[FILE_MAX]; - BLI_strncpy(str, filepath, sizeof(str)); + STRNCPY(str, filepath); BLI_path_abs(str, G.main->name); /* first search an identical filepath */ for (ima = G.main->image.first; ima; ima = ima->id.next) { if (ima->source != IMA_SRC_VIEWER && ima->source != IMA_SRC_GENERATED) { - BLI_strncpy(strtest, ima->name, sizeof(ima->name)); + STRNCPY(strtest, ima->name); BLI_path_abs(strtest, ID_BLEND_PATH(G.main, &ima->id)); if (BLI_path_cmp(strtest, str) == 0) { @@ -669,7 +669,7 @@ static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char if (colorspace_settings->name[0] == '\0') { const char *colorspace = IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DEFAULT_FLOAT); - BLI_strncpy(colorspace_settings->name, colorspace, sizeof(colorspace_settings->name)); + STRNCPY(colorspace_settings->name, colorspace); } if (ibuf != NULL) { @@ -683,7 +683,7 @@ static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char if (colorspace_settings->name[0] == '\0') { const char *colorspace = IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DEFAULT_BYTE); - BLI_strncpy(colorspace_settings->name, colorspace, sizeof(colorspace_settings->name)); + STRNCPY(colorspace_settings->name, colorspace); } if (ibuf != NULL) { @@ -696,7 +696,7 @@ static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char return NULL; } - BLI_strncpy(ibuf->name, name, sizeof(ibuf->name)); + STRNCPY(ibuf->name, name); ibuf->userflags |= IB_BITMAPDIRTY; switch (gen_type) { @@ -726,7 +726,7 @@ Image *BKE_image_add_generated( int view_id; const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME}; - /* BLI_strncpy(ima->name, name, FILE_MAX); */ /* don't do this, this writes in ain invalid filepath! */ + /* STRNCPY(ima->name, name); */ /* don't do this, this writes in ain invalid filepath! */ ima->gen_x = width; ima->gen_y = height; ima->gen_type = gen_type; @@ -767,7 +767,7 @@ Image *BKE_image_add_from_imbuf(ImBuf *ibuf, const char *name) ima = image_alloc(G.main, name, IMA_SRC_FILE, IMA_TYPE_IMAGE); if (ima) { - BLI_strncpy(ima->name, ibuf->name, FILE_MAX); + STRNCPY(ima->name, ibuf->name); image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0); ima->ok = IMA_OK_LOADED; } @@ -813,7 +813,7 @@ static void image_memorypack_multiview(Image *ima) pf->size = ibuf->encodedsize; imapf = MEM_mallocN(sizeof(ImagePackedFile), "Image PackedFile"); - BLI_strncpy(imapf->filepath, iv->filepath, sizeof(imapf->filepath)); + STRNCPY(imapf->filepath, iv->filepath); imapf->packedfile = pf; BLI_addtail(&ima->packedfiles, imapf); @@ -863,7 +863,7 @@ void BKE_image_memorypack(Image *ima) pf->size = ibuf->encodedsize; imapf = MEM_mallocN(sizeof(ImagePackedFile), "Image PackedFile"); - BLI_strncpy(imapf->filepath, ima->name, sizeof(imapf->filepath)); + STRNCPY(imapf->filepath, ima->name); imapf->packedfile = pf; BLI_addtail(&ima->packedfiles, imapf); @@ -889,7 +889,7 @@ void BKE_image_packfiles(ReportList *reports, Image *ima, const char *basepath) BLI_addtail(&ima->packedfiles, imapf); imapf->packedfile = newPackedFile(reports, ima->name, basepath); if (imapf->packedfile) { - BLI_strncpy(imapf->filepath, ima->name, sizeof(imapf->filepath)); + STRNCPY(imapf->filepath, ima->name); } else { BLI_freelinkN(&ima->packedfiles, imapf); @@ -903,7 +903,7 @@ void BKE_image_packfiles(ReportList *reports, Image *ima, const char *basepath) imapf->packedfile = newPackedFile(reports, iv->filepath, basepath); if (imapf->packedfile) { - BLI_strncpy(imapf->filepath, iv->filepath, sizeof(imapf->filepath)); + STRNCPY(imapf->filepath, iv->filepath); } else { BLI_freelinkN(&ima->packedfiles, imapf); @@ -923,7 +923,7 @@ void BKE_image_packfiles_from_mem(ReportList *reports, Image *ima, char *data, c ImagePackedFile *imapf = MEM_mallocN(sizeof(ImagePackedFile), __func__); BLI_addtail(&ima->packedfiles, imapf); imapf->packedfile = newPackedFileMemory(data, data_len); - BLI_strncpy(imapf->filepath, ima->name, sizeof(imapf->filepath)); + STRNCPY(imapf->filepath, ima->name); } } @@ -1652,7 +1652,7 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d time_t t; if (scene->r.stamp & R_STAMP_FILENAME) { - BLI_snprintf(stamp_data->file, sizeof(stamp_data->file), do_prefix ? "File %s" : "%s", G.relbase_valid ? G.main->name : ""); + SNPRINTF(stamp_data->file, do_prefix ? "File %s" : "%s", G.relbase_valid ? G.main->name : ""); } else { stamp_data->file[0] = '\0'; @@ -1660,7 +1660,7 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d if (scene->r.stamp & R_STAMP_NOTE) { /* Never do prefix for Note */ - BLI_snprintf(stamp_data->note, sizeof(stamp_data->note), "%s", scene->r.stamp_udata); + SNPRINTF(stamp_data->note, "%s", scene->r.stamp_udata); } else { stamp_data->note[0] = '\0'; @@ -1669,8 +1669,9 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d if (scene->r.stamp & R_STAMP_DATE) { t = time(NULL); tl = localtime(&t); - BLI_snprintf(text, sizeof(text), "%04d/%02d/%02d %02d:%02d:%02d", tl->tm_year + 1900, tl->tm_mon + 1, tl->tm_mday, tl->tm_hour, tl->tm_min, tl->tm_sec); - BLI_snprintf(stamp_data->date, sizeof(stamp_data->date), do_prefix ? "Date %s" : "%s", text); + SNPRINTF(text, "%04d/%02d/%02d %02d:%02d:%02d", + tl->tm_year + 1900, tl->tm_mon + 1, tl->tm_mday, tl->tm_hour, tl->tm_min, tl->tm_sec); + SNPRINTF(stamp_data->date, do_prefix ? "Date %s" : "%s", text); } else { stamp_data->date[0] = '\0'; @@ -1679,10 +1680,10 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d if (use_dynamic && scene->r.stamp & R_STAMP_MARKER) { const char *name = BKE_scene_find_last_marker_name(scene, CFRA); - if (name) BLI_strncpy(text, name, sizeof(text)); - else BLI_strncpy(text, "", sizeof(text)); + if (name) STRNCPY(text, name); + else STRNCPY(text, ""); - BLI_snprintf(stamp_data->marker, sizeof(stamp_data->marker), do_prefix ? "Marker %s" : "%s", text); + SNPRINTF(stamp_data->marker, do_prefix ? "Marker %s" : "%s", text); } else { stamp_data->marker[0] = '\0'; @@ -1691,7 +1692,7 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d if (use_dynamic && scene->r.stamp & R_STAMP_TIME) { const short timecode_style = USER_TIMECODE_SMPTE_FULL; BLI_timecode_string_from_time(text, sizeof(text), 0, FRA2TIME(scene->r.cfra), FPS, timecode_style); - BLI_snprintf(stamp_data->time, sizeof(stamp_data->time), do_prefix ? "Timecode %s" : "%s", text); + SNPRINTF(stamp_data->time, do_prefix ? "Timecode %s" : "%s", text); } else { stamp_data->time[0] = '\0'; @@ -1704,24 +1705,24 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d if (scene->r.efra > 9) digits = integer_digits_i(scene->r.efra); - BLI_snprintf(fmtstr, sizeof(fmtstr), do_prefix ? "Frame %%0%di" : "%%0%di", digits); - BLI_snprintf(stamp_data->frame, sizeof(stamp_data->frame), fmtstr, scene->r.cfra); + SNPRINTF(fmtstr, do_prefix ? "Frame %%0%di" : "%%0%di", digits); + SNPRINTF(stamp_data->frame, fmtstr, scene->r.cfra); } else { stamp_data->frame[0] = '\0'; } if (scene->r.stamp & R_STAMP_FRAME_RANGE) { - BLI_snprintf(stamp_data->frame_range, sizeof(stamp_data->frame), - do_prefix ? "Frame Range %d:%d" : "%d:%d", - scene->r.sfra, scene->r.efra); + SNPRINTF(stamp_data->frame_range, + do_prefix ? "Frame Range %d:%d" : "%d:%d", + scene->r.sfra, scene->r.efra); } else { stamp_data->frame_range[0] = '\0'; } if (use_dynamic && scene->r.stamp & R_STAMP_CAMERA) { - BLI_snprintf(stamp_data->camera, sizeof(stamp_data->camera), do_prefix ? "Camera %s" : "%s", camera ? camera->id.name + 2 : ""); + SNPRINTF(stamp_data->camera, do_prefix ? "Camera %s" : "%s", camera ? camera->id.name + 2 : ""); } else { stamp_data->camera[0] = '\0'; @@ -1729,20 +1730,20 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d if (use_dynamic && scene->r.stamp & R_STAMP_CAMERALENS) { if (camera && camera->type == OB_CAMERA) { - BLI_snprintf(text, sizeof(text), "%.2f", ((Camera *)camera->data)->lens); + SNPRINTF(text, "%.2f", ((Camera *)camera->data)->lens); } else { - BLI_strncpy(text, "", sizeof(text)); + STRNCPY(text, ""); } - BLI_snprintf(stamp_data->cameralens, sizeof(stamp_data->cameralens), do_prefix ? "Lens %s" : "%s", text); + SNPRINTF(stamp_data->cameralens, do_prefix ? "Lens %s" : "%s", text); } else { stamp_data->cameralens[0] = '\0'; } if (scene->r.stamp & R_STAMP_SCENE) { - BLI_snprintf(stamp_data->scene, sizeof(stamp_data->scene), do_prefix ? "Scene %s" : "%s", scene->id.name + 2); + SNPRINTF(stamp_data->scene, do_prefix ? "Scene %s" : "%s", scene->id.name + 2); } else { stamp_data->scene[0] = '\0'; @@ -1751,10 +1752,10 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d if (use_dynamic && scene->r.stamp & R_STAMP_SEQSTRIP) { Sequence *seq = BKE_sequencer_foreground_frame_get(scene, scene->r.cfra); - if (seq) BLI_strncpy(text, seq->name + 2, sizeof(text)); - else BLI_strncpy(text, "", sizeof(text)); + if (seq) STRNCPY(text, seq->name + 2); + else STRNCPY(text, ""); - BLI_snprintf(stamp_data->strip, sizeof(stamp_data->strip), do_prefix ? "Strip %s" : "%s", text); + SNPRINTF(stamp_data->strip, do_prefix ? "Strip %s" : "%s", text); } else { stamp_data->strip[0] = '\0'; @@ -1767,21 +1768,21 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d if (use_dynamic && stats && (scene->r.stamp & R_STAMP_RENDERTIME)) { BLI_timecode_string_from_time_simple(text, sizeof(text), stats->lastframetime); - BLI_snprintf(stamp_data->rendertime, sizeof(stamp_data->rendertime), do_prefix ? "RenderTime %s" : "%s", text); + SNPRINTF(stamp_data->rendertime, do_prefix ? "RenderTime %s" : "%s", text); } else { stamp_data->rendertime[0] = '\0'; } if (use_dynamic && stats && (scene->r.stamp & R_STAMP_MEMORY)) { - BLI_snprintf(stamp_data->memory, sizeof(stamp_data->memory), do_prefix ? "Peak Memory %.2fM" : "%.2fM", stats->mem_peak); + SNPRINTF(stamp_data->memory, do_prefix ? "Peak Memory %.2fM" : "%.2fM", stats->mem_peak); } else { stamp_data->memory[0] = '\0'; } } if (scene->r.stamp & R_STAMP_FRAME_RANGE) { - BLI_snprintf(stamp_data->frame_range, sizeof(stamp_data->frame_range), + SNPRINTF(stamp_data->frame_range, do_prefix ? "Frame Range %d:%d" : "%d:%d", scene->r.sfra, scene->r.efra); } else { @@ -1795,73 +1796,73 @@ static void stampdata_from_template(StampData *stamp_data, const StampData *stamp_data_template) { if (scene->r.stamp & R_STAMP_FILENAME) { - BLI_snprintf(stamp_data->file, sizeof(stamp_data->file), "File %s", stamp_data_template->file); + SNPRINTF(stamp_data->file, "File %s", stamp_data_template->file); } else { stamp_data->file[0] = '\0'; } if (scene->r.stamp & R_STAMP_NOTE) { - BLI_snprintf(stamp_data->note, sizeof(stamp_data->note), "%s", stamp_data_template->note); + SNPRINTF(stamp_data->note, "%s", stamp_data_template->note); } else { stamp_data->note[0] = '\0'; } if (scene->r.stamp & R_STAMP_DATE) { - BLI_snprintf(stamp_data->date, sizeof(stamp_data->date), "Date %s", stamp_data_template->date); + SNPRINTF(stamp_data->date, "Date %s", stamp_data_template->date); } else { stamp_data->date[0] = '\0'; } if (scene->r.stamp & R_STAMP_MARKER) { - BLI_snprintf(stamp_data->marker, sizeof(stamp_data->marker), "Marker %s", stamp_data_template->marker); + SNPRINTF(stamp_data->marker, "Marker %s", stamp_data_template->marker); } else { stamp_data->marker[0] = '\0'; } if (scene->r.stamp & R_STAMP_TIME) { - BLI_snprintf(stamp_data->time, sizeof(stamp_data->time), "Timecode %s", stamp_data_template->time); + SNPRINTF(stamp_data->time, "Timecode %s", stamp_data_template->time); } else { stamp_data->time[0] = '\0'; } if (scene->r.stamp & R_STAMP_FRAME) { - BLI_snprintf(stamp_data->frame, sizeof(stamp_data->frame), "Frame %s", stamp_data_template->frame); + SNPRINTF(stamp_data->frame, "Frame %s", stamp_data_template->frame); } else { stamp_data->frame[0] = '\0'; } if (scene->r.stamp & R_STAMP_CAMERA) { - BLI_snprintf(stamp_data->camera, sizeof(stamp_data->camera), "Camera %s", stamp_data_template->camera); + SNPRINTF(stamp_data->camera, "Camera %s", stamp_data_template->camera); } else { stamp_data->camera[0] = '\0'; } if (scene->r.stamp & R_STAMP_CAMERALENS) { - BLI_snprintf(stamp_data->cameralens, sizeof(stamp_data->cameralens), "Lens %s", stamp_data_template->cameralens); + SNPRINTF(stamp_data->cameralens, "Lens %s", stamp_data_template->cameralens); } else { stamp_data->cameralens[0] = '\0'; } if (scene->r.stamp & R_STAMP_SCENE) { - BLI_snprintf(stamp_data->scene, sizeof(stamp_data->scene), "Scene %s", stamp_data_template->scene); + SNPRINTF(stamp_data->scene, "Scene %s", stamp_data_template->scene); } else { stamp_data->scene[0] = '\0'; } if (scene->r.stamp & R_STAMP_SEQSTRIP) { - BLI_snprintf(stamp_data->strip, sizeof(stamp_data->strip), "Strip %s", stamp_data_template->strip); + SNPRINTF(stamp_data->strip, "Strip %s", stamp_data_template->strip); } else { stamp_data->strip[0] = '\0'; } if (scene->r.stamp & R_STAMP_RENDERTIME) { - BLI_snprintf(stamp_data->rendertime, sizeof(stamp_data->rendertime), "RenderTime %s", stamp_data_template->rendertime); + SNPRINTF(stamp_data->rendertime, "RenderTime %s", stamp_data_template->rendertime); } else { stamp_data->rendertime[0] = '\0'; } if (scene->r.stamp & R_STAMP_MEMORY) { - BLI_snprintf(stamp_data->memory, sizeof(stamp_data->memory), "Peak Memory %s", stamp_data_template->memory); + SNPRINTF(stamp_data->memory, "Peak Memory %s", stamp_data_template->memory); } else { stamp_data->memory[0] = '\0'; @@ -2196,8 +2197,8 @@ void BKE_render_result_stamp_data(RenderResult *rr, const char *key, const char stamp_data = rr->stamp_data; StampDataCustomField *field = MEM_mallocN(sizeof(StampDataCustomField), "StampData Custom Field"); - BLI_strncpy(field->key, key, sizeof(field->key)); - BLI_strncpy(field->value, value, sizeof(field->value)); + STRNCPY(field->key, key); + STRNCPY(field->value, value); BLI_addtail(&stamp_data->custom_fields, field); } @@ -3000,7 +3001,7 @@ static void image_init_multilayer_multiview(Image *ima, RenderResult *rr) if (rr) { for (RenderView *rv = rr->views.first; rv; rv = rv->next) { ImageView *iv = MEM_callocN(sizeof(ImageView), "Viewer Image View"); - BLI_strncpy(iv->name, rv->name, sizeof(iv->name)); + STRNCPY(iv->name, rv->name); BLI_addtail(&ima->views, iv); } } @@ -3081,8 +3082,8 @@ static void image_add_view(Image *ima, const char *viewname, const char *filepat ImageView *iv; iv = MEM_mallocN(sizeof(ImageView), "Viewer Image View"); - BLI_strncpy(iv->name, viewname, sizeof(iv->name)); - BLI_strncpy(iv->filepath, filepath, sizeof(iv->filepath)); + STRNCPY(iv->name, viewname); + STRNCPY(iv->filepath, filepath); /* For stereo drawing we need to ensure: * STEREO_LEFT_NAME == STEREO_LEFT_ID and @@ -3532,7 +3533,7 @@ static ImBuf *load_image_single( ImagePackedFile *imapf = MEM_mallocN(sizeof(ImagePackedFile), "Image Packefile"); BLI_addtail(&ima->packedfiles, imapf); - BLI_strncpy(imapf->filepath, filepath, sizeof(imapf->filepath)); + STRNCPY(imapf->filepath, filepath); imapf->packedfile = newPackedFile(NULL, filepath, ID_BLEND_PATH(G.main, &ima->id)); } } @@ -4687,7 +4688,7 @@ static void image_update_views_format(Image *ima, ImageUser *iuser) for (srv = scene->r.views.first; srv; srv = srv->next) { if (BKE_scene_multiview_is_render_view_active(&scene->r, srv)) { char filepath[FILE_MAX]; - BLI_snprintf(filepath, sizeof(filepath), "%s%s%s", prefix, srv->suffix, ext); + SNPRINTF(filepath, "%s%s%s", prefix, srv->suffix, ext); image_add_view(ima, srv->name, filepath); } } @@ -4698,7 +4699,7 @@ static void image_update_views_format(Image *ima, ImageUser *iuser) int file; char str[FILE_MAX]; - BLI_strncpy(str, iv->filepath, sizeof(str)); + STRNCPY(str, iv->filepath); BLI_path_abs(str, G.main->name); /* exists? */ -- cgit v1.2.3