snprintf() workaround for Win

VS 2010 doesn't have snprintf().
As a temporary workaround (until we move to VS 2015)
#define snprintf as _snprintf (which doesn't null-terminate
if buffer is too small).
This is at least no worse than using sprintf(), which we were doing.
This commit is contained in:
David Anderson 2016-02-17 23:22:49 -08:00
parent 87769d4acb
commit b3d3fc4f89
2 changed files with 9 additions and 2 deletions

View File

@ -903,7 +903,7 @@ void CSimpleTaskPanel::FindSlideShowFiles(TaskSelectionData *selData) {
if (state_result) {
url_to_project_dir(state_result->project->master_url, proj_dir, sizeof(proj_dir));
for(j=0; j<99; ++j) {
snprintf(fileName, sizeof(fileName), "%s/slideshow_%s_%02d", urlDirectory, state_result->app->name, j);
snprintf(fileName, sizeof(fileName), "%s/slideshow_%s_%02d", proj_dir, state_result->app->name, j);
if(boinc_resolve_filename(fileName, resolvedFileName, sizeof(resolvedFileName)) == 0) {
if (boinc_file_exists(resolvedFileName)) {
selData->slideShowFileNames.Add(wxString(resolvedFileName,wxConvUTF8));
@ -915,7 +915,7 @@ void CSimpleTaskPanel::FindSlideShowFiles(TaskSelectionData *selData) {
if ( selData->slideShowFileNames.size() == 0 ) {
for(j=0; j<99; ++j) {
snprintf(fileName, sizeof(fileName), "%s/slideshow_%02d", urlDirectory, j);
snprintf(fileName, sizeof(fileName), "%s/slideshow_%02d", proj_dir, j);
if(boinc_resolve_filename(fileName, resolvedFileName, sizeof(resolvedFileName)) == 0) {
if (boinc_file_exists(resolvedFileName)) {
selData->slideShowFileNames.Add(wxString(resolvedFileName,wxConvUTF8));

View File

@ -61,4 +61,11 @@ inline int strcasecmp(const char* s1, const char* s2) {
#define safe_strcpy(x, y) strlcpy(x, y, sizeof(x))
#define safe_strcat(x, y) strlcat(x, y, sizeof(x))
#ifdef _WIN32
#define snprintf _snprintf
// Yucky! _snprintf() is not the same as snprintf();
// it doesn't null-terminate if buffer is too small.
// This is a workaround until we switch to VS2015, which has sprintf()
#endif
#endif