misc minor edits.

- pass string size to BLI_timestr() to avoid possible buffer overrun.
- quiet warning for mingw.
- include guards for windows utf conversion funcs.
- fix for mistage in edge-angle-selection check.
- some style cleanup.
This commit is contained in:
Campbell Barton
2013-03-29 06:25:22 +00:00
parent ab41583bc2
commit 1777a69818
28 changed files with 78 additions and 70 deletions

View File

@@ -576,7 +576,7 @@ void BlenderSession::update_status_progress()
timestatus += ", " + b_rlay_name; timestatus += ", " + b_rlay_name;
timestatus += " | "; timestatus += " | ";
BLI_timestr(total_time, time_str); BLI_timestr(total_time, time_str, sizeof(time_str));
timestatus += "Elapsed: " + string(time_str) + " | "; timestatus += "Elapsed: " + string(time_str) + " | ";
if(substatus.size() > 0) if(substatus.size() > 0)

View File

@@ -30,7 +30,7 @@
* todo: clean this up ... */ * todo: clean this up ... */
extern "C" { extern "C" {
void BLI_timestr(double _time, char *str); void BLI_timestr(double _time, char *str, size_t maxlen);
void BKE_image_user_frame_calc(void *iuser, int cfra, int fieldnr); void BKE_image_user_frame_calc(void *iuser, int cfra, int fieldnr);
void BKE_image_user_file_path(void *iuser, void *ima, char *path); void BKE_image_user_file_path(void *iuser, void *ima, char *path);
unsigned char *BKE_image_get_pixels_for_frame(void *image, int frame); unsigned char *BKE_image_get_pixels_for_frame(void *image, int frame);

View File

@@ -23,6 +23,9 @@
* ***** END GPL LICENSE BLOCK ***** * ***** END GPL LICENSE BLOCK *****
*/ */
#ifndef __UTF_WINFUNC_H__
#define __UTF_WINFUNC_H__
#ifndef WIN32 #ifndef WIN32
# error "This file can only compile on windows" # error "This file can only compile on windows"
#endif #endif
@@ -41,3 +44,5 @@ int uput_getenv(const char *varname, char * value, size_t buffsize);
int uputenv(const char *name, const char *value); int uputenv(const char *name, const char *value);
int umkdir(const char *pathname); int umkdir(const char *pathname);
#endif /* __UTF_WINFUNC_H__ */

View File

@@ -23,6 +23,9 @@
* ***** END GPL LICENSE BLOCK ***** * ***** END GPL LICENSE BLOCK *****
*/ */
#ifndef __UTFCONV_H__
#define __UTFCONV_H__
#include <wchar.h> #include <wchar.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -98,3 +101,5 @@ wchar_t *alloc_utf16_from_8(const char *in8, size_t add);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* __UTFCONV_H__ */

View File

@@ -1601,7 +1601,7 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d
RenderStats *stats = re ? RE_GetStats(re) : NULL; RenderStats *stats = re ? RE_GetStats(re) : NULL;
if (stats && (scene->r.stamp & R_STAMP_RENDERTIME)) { if (stats && (scene->r.stamp & R_STAMP_RENDERTIME)) {
BLI_timestr(stats->lastframetime, text); BLI_timestr(stats->lastframetime, text, sizeof(text));
BLI_snprintf(stamp_data->rendertime, sizeof(stamp_data->rendertime), do_prefix ? "RenderTime %s" : "%s", text); BLI_snprintf(stamp_data->rendertime, sizeof(stamp_data->rendertime), do_prefix ? "RenderTime %s" : "%s", text);
} }

View File

@@ -150,7 +150,7 @@ __attribute__((warn_unused_result))
__attribute__((nonnull)) __attribute__((nonnull))
#endif #endif
; ;
void BLI_timestr(double _time, char *str) void BLI_timestr(double _time, char *str, size_t maxlen)
#ifdef __GNUC__ #ifdef __GNUC__
__attribute__((nonnull)) __attribute__((nonnull))
#endif #endif

View File

@@ -490,22 +490,20 @@ int BLI_natstrcmp(const char *s1, const char *s2)
return 0; return 0;
} }
void BLI_timestr(double _time, char *str) void BLI_timestr(double _time, char *str, size_t maxlen)
{ {
/* format 00:00:00.00 (hr:min:sec) string has to be 12 long */ /* format 00:00:00.00 (hr:min:sec) string has to be 12 long */
int hr = ( (int) _time) / (60 * 60); int hr = ( (int) _time) / (60 * 60);
int min = (((int) _time) / 60 ) % 60; int min = (((int) _time) / 60 ) % 60;
int sec = ( (int) (_time)) % 60; int sec = ( (int) _time) % 60;
int hun = ( (int) (_time * 100.0)) % 100; int hun = ( (int) (_time * 100.0)) % 100;
if (hr) { if (hr) {
sprintf(str, "%.2d:%.2d:%.2d.%.2d", hr, min, sec, hun); BLI_snprintf(str, maxlen, "%.2d:%.2d:%.2d.%.2d", hr, min, sec, hun);
} }
else { else {
sprintf(str, "%.2d:%.2d.%.2d", min, sec, hun); BLI_snprintf(str, maxlen, "%.2d:%.2d.%.2d", min, sec, hun);
} }
str[11] = 0;
} }
/* determine the length of a fixed-size string */ /* determine the length of a fixed-size string */

View File

@@ -435,7 +435,7 @@ void ExecutionGroup::printBackgroundStats(void)
fprintf(stdout, "Mem:%.2fM (%.2fM, Peak %.2fM) ", fprintf(stdout, "Mem:%.2fM (%.2fM, Peak %.2fM) ",
megs_used_memory, mmap_used_memory, megs_peak_memory); megs_used_memory, mmap_used_memory, megs_peak_memory);
BLI_timestr(execution_time, timestr); BLI_timestr(execution_time, timestr, sizeof(timestr));
printf("| Elapsed %s ", timestr); printf("| Elapsed %s ", timestr);
printf("| Tree %s, Tile %d-%d ", this->m_bTree->id.name + 2, printf("| Tree %s, Tile %d-%d ", this->m_bTree->id.name + 2,
this->m_chunksFinished, this->m_numberOfChunks); this->m_chunksFinished, this->m_numberOfChunks);

View File

@@ -394,7 +394,7 @@ static int dynamicPaint_initBake(struct bContext *C, struct wmOperator *op)
/* Format time string */ /* Format time string */
char time_str[30]; char time_str[30];
double time = PIL_check_seconds_timer() - timer; double time = PIL_check_seconds_timer() - timer;
BLI_timestr(time, time_str); BLI_timestr(time, time_str, sizeof(time_str));
/* Show bake info */ /* Show bake info */
BKE_reportf(op->reports, RPT_INFO, "Bake complete! (%s)", time_str); BKE_reportf(op->reports, RPT_INFO, "Bake complete! (%s)", time_str);

View File

@@ -311,7 +311,7 @@ static void make_renderinfo_string(RenderStats *rs, Scene *scene, char *str)
spos += sprintf(spos, IFACE_("Blur %d "), rs->curblur); spos += sprintf(spos, IFACE_("Blur %d "), rs->curblur);
} }
BLI_timestr(rs->lastframetime, info_time_str); BLI_timestr(rs->lastframetime, info_time_str, sizeof(info_time_str));
spos += sprintf(spos, IFACE_("Time:%s "), info_time_str); spos += sprintf(spos, IFACE_("Time:%s "), info_time_str);
if (rs->curfsa) if (rs->curfsa)

View File

@@ -2671,8 +2671,8 @@ static void draw_em_measure_stats(View3D *v3d, Object *ob, BMEditMesh *em, UnitS
/* special case, this is useful to show when vertes connected to this edge via a /* special case, this is useful to show when vertes connected to this edge via a
* face are being transformed */ * face are being transformed */
BM_elem_flag_test(l_a->next->next->v, BM_ELEM_SELECT) || BM_elem_flag_test(l_a->next->next->v, BM_ELEM_SELECT) ||
BM_elem_flag_test(l_b->prev->v, BM_ELEM_SELECT) || BM_elem_flag_test(l_a->prev->v, BM_ELEM_SELECT) ||
BM_elem_flag_test(l_a->next->next->v, BM_ELEM_SELECT) || BM_elem_flag_test(l_b->next->next->v, BM_ELEM_SELECT) ||
BM_elem_flag_test(l_b->prev->v, BM_ELEM_SELECT) BM_elem_flag_test(l_b->prev->v, BM_ELEM_SELECT)
))) )))
{ {

View File

@@ -2357,12 +2357,12 @@ static int do_write_image_or_movie(Render *re, Main *bmain, Scene *scene, bMovie
render_time = re->i.lastframetime; render_time = re->i.lastframetime;
re->i.lastframetime = PIL_check_seconds_timer() - re->i.starttime; re->i.lastframetime = PIL_check_seconds_timer() - re->i.starttime;
BLI_timestr(re->i.lastframetime, name); BLI_timestr(re->i.lastframetime, name, sizeof(name));
printf(" Time: %s", name); printf(" Time: %s", name);
BLI_callback_exec(G.main, NULL, BLI_CB_EVT_RENDER_STATS); BLI_callback_exec(G.main, NULL, BLI_CB_EVT_RENDER_STATS);
BLI_timestr(re->i.lastframetime - render_time, name); BLI_timestr(re->i.lastframetime - render_time, name, sizeof(name));
printf(" (Saving: %s)\n", name); printf(" (Saving: %s)\n", name);
fputc('\n', stdout); fputc('\n', stdout);

View File

@@ -956,7 +956,7 @@ void wm_autosave_location(char *filepath)
{ {
char pidstr[32]; char pidstr[32];
#ifdef WIN32 #ifdef WIN32
char *savedir; const char *savedir;
#endif #endif
BLI_snprintf(pidstr, sizeof(pidstr), "%d.blend", abs(getpid())); BLI_snprintf(pidstr, sizeof(pidstr), "%d.blend", abs(getpid()));