From b3d3fc4f89156d76f96a6e6e753306889dc17588 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 17 Feb 2016 23:22:49 -0800 Subject: [PATCH] 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. --- clientgui/sg_TaskPanel.cpp | 4 ++-- lib/str_replace.h | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/clientgui/sg_TaskPanel.cpp b/clientgui/sg_TaskPanel.cpp index d9788f1f9c..2bb7c19d4a 100644 --- a/clientgui/sg_TaskPanel.cpp +++ b/clientgui/sg_TaskPanel.cpp @@ -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)); diff --git a/lib/str_replace.h b/lib/str_replace.h index 7d6a303363..01229b562d 100644 --- a/lib/str_replace.h +++ b/lib/str_replace.h @@ -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