From 6f4b8e5d438ee6f1549c60ad6f8417fa80bff55a Mon Sep 17 00:00:00 2001 From: davidpanderson Date: Wed, 22 Mar 2023 14:23:14 -0700 Subject: [PATCH] Fix some compile warnings on Win (VS 2022). Remove outdated stuff (e.g. VS has snprintf() now). I'd like to have a clean build (no warnings) on both VS and gcc. Currently VS has a bunch of printf code warnings in diagnostics.cpp, diagnostics_win.cpp, and stackwalker_win.cpp. These should be easy to fix. gcc has a bunch of sprintf buffer-size warnings, not easy to fix. There are lots of warnings in zip (to be fixed with vcpkg?) and in old graphics code. --- api/boinc_api.cpp | 4 +++- client/client_types.cpp | 4 ++-- client/hostinfo_win.cpp | 2 +- lib/boinc_stdio.h | 4 ++++ lib/boinc_win.h | 6 +----- lib/str_replace.h | 9 +-------- 6 files changed, 12 insertions(+), 17 deletions(-) diff --git a/api/boinc_api.cpp b/api/boinc_api.cpp index 19835f2fdd..bb4a1d2925 100644 --- a/api/boinc_api.cpp +++ b/api/boinc_api.cpp @@ -1023,13 +1023,15 @@ int boinc_wu_cpu_time(double& cpu_t) { // Suspend this job. // Can be called from either timer or worker thread. // -static int suspend_activities(bool called_from_worker) { #ifdef VERBOSE +static int suspend_activities(bool called_from_worker) { char log_buf[256]; fprintf(stderr, "%s suspend_activities() called from %s\n", boinc_msg_prefix(log_buf, sizeof(log_buf)), called_from_worker?"worker thread":"timer thread" ); +#else +static int suspend_activities(bool) { #endif #ifdef _WIN32 static vector pids; diff --git a/client/client_types.cpp b/client/client_types.cpp index 2977ef7863..af1ab5a225 100644 --- a/client/client_types.cpp +++ b/client/client_types.cpp @@ -402,13 +402,13 @@ int FILE_INFO::parse(XML_PARSER& xp) { retval = pfxp->parse(xp); #ifdef SIM delete pfxp; - continue; -#endif +#else if (!retval) { pers_file_xfer = pfxp; } else { delete pfxp; } +#endif continue; } if (xp.match_tag("file_xfer")) { diff --git a/client/hostinfo_win.cpp b/client/hostinfo_win.cpp index d4551f9034..7e5daa20b4 100644 --- a/client/hostinfo_win.cpp +++ b/client/hostinfo_win.cpp @@ -472,7 +472,7 @@ int get_os_information( } - snprintf_s( szVersion, sizeof(szVersion), ", (%.2u.%.2u.%.4u.%.2u)", + snprintf( szVersion, sizeof(szVersion), ", (%.2u.%.2u.%.4u.%.2u)", osvi.dwMajorVersion, osvi.dwMinorVersion, (osvi.dwBuildNumber & 0xFFFF), 0 ); diff --git a/lib/boinc_stdio.h b/lib/boinc_stdio.h index 77b8aefadd..0bde4272a7 100644 --- a/lib/boinc_stdio.h +++ b/lib/boinc_stdio.h @@ -75,8 +75,12 @@ namespace boinc { inline int fileno(FILE *f) { #ifdef _USING_FCGI_ return FCGI_fileno(f); +#else +#ifdef _WIN32 + return ::_fileno(f); #else return ::fileno(f); +#endif #endif } diff --git a/lib/boinc_win.h b/lib/boinc_win.h index 0bde22a49e..e9a3f3ddc3 100644 --- a/lib/boinc_win.h +++ b/lib/boinc_win.h @@ -27,7 +27,7 @@ #ifdef _MSC_VER #pragma warning(disable: 4996) // deprecated function names -#pragma warning(disable: 4127) // constant conditional expression +//#pragma warning(disable: 4127) // constant conditional expression #pragma warning(disable: 4244) // conversion from int to char #define chdir _chdir #define finite _finite @@ -38,10 +38,6 @@ #define stricmp _stricmp #define strtime _strtime #define unlink _unlink -#define snprintf_s _snprintf_s -#if _MSC_VER < 1900 -#define snprintf _snprintf -#endif #endif #ifdef __MINGW32__ diff --git a/lib/str_replace.h b/lib/str_replace.h index d3b39b2785..21aecd71f4 100644 --- a/lib/str_replace.h +++ b/lib/str_replace.h @@ -1,6 +1,6 @@ // This file is part of BOINC. // http://boinc.berkeley.edu -// Copyright (C) 2008 University of California +// Copyright (C) 2023 University of California // // BOINC is free software; you can redistribute it and/or modify it // under the terms of the GNU Lesser General Public License @@ -56,11 +56,4 @@ inline int strcasecmp(const char* s1, const char* s2) { } #endif -#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