From 1b6fe31e9c64de0571b4390353504615804bbae8 Mon Sep 17 00:00:00 2001 From: Vitalii Koshura Date: Tue, 10 Sep 2024 00:57:52 +0200 Subject: [PATCH 01/16] clientscr: fix float <-> double conversion warnings Signed-off-by: Vitalii Koshura --- clientscr/ss_app.cpp | 50 ++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/clientscr/ss_app.cpp b/clientscr/ss_app.cpp index 3cb97684c50..183b1c86515 100644 --- a/clientscr/ss_app.cpp +++ b/clientscr/ss_app.cpp @@ -179,7 +179,7 @@ static void init_lights() { static void draw_logo(float* pos, float alpha) { if (logo.present) { - float size[3] = {.6, .4, 0}; + float size[3] = {.6f, .4f, 0}; logo.draw(pos, size, ALIGN_CENTER, ALIGN_CENTER, alpha); } } @@ -188,22 +188,22 @@ void show_result(RESULT* r, float x, float& y, float alpha) { PROGRESS_2D progress; char buf[256]; ttf_render_string(x, y, 0, TASK_PROJ_SIZE, white, (char*)r->project->project_name.c_str()); - y -= .02; + y -= .02f; float prog_pos[] = {x, y, 0}; - float prog_c[] = {.5, .4, .1, alpha/2}; - float prog_ci[] = {.1, .8, .2, alpha}; - progress.init(prog_pos, .4, -.01, -0.008, prog_c, prog_ci); + float prog_c[] = {.5f, .4f, .1f, alpha/2}; + float prog_ci[] = {.1f, .8f, .2f, alpha}; + progress.init(prog_pos, .4f, -.01f, -0.008f, prog_c, prog_ci); progress.draw(r->fraction_done); snprintf(buf, sizeof(buf), "%.2f%% ", r->fraction_done*100); ttf_render_string(x+.41, y, 0, TASK_INFO_SIZE, white, buf); - y -= .03; - x += .05; + y -= .03f; + x += .05f; snprintf(buf, sizeof(buf), "Elapsed: %.0f sec Remaining: %.0f sec", r->elapsed_time, r->estimated_cpu_time_remaining); ttf_render_string(x, y, 0, TASK_INFO_SIZE, white, buf); - y -= .03; + y -= .03f; snprintf(buf, sizeof(buf), "App: %s Task: %s", r->app->user_friendly_name, r->wup->name); ttf_render_string(x, y, 0, TASK_INFO_SIZE, white, buf); - y -= .03; + y -= .03f; } #if 0 @@ -224,44 +224,44 @@ void show_coords() { #endif void show_project(unsigned int index, float /*alpha*/) { - float x=.2, y=.6; + float x=.2f, y=.6f; char buf[1024]; ttf_render_string(x, y, 0, PROJ_INTRO_SIZE, white, "This computer is participating in"); - y -= .07; + y -= .07f; PROJECT *p = cc_state.projects[index]; ttf_render_string(x, y, 0, PROJ_NAME_SIZE, white, (char*)p->project_name.c_str()); - y -= .07; + y -= .07f; ttf_render_string(x, y, 0, PROJ_INFO_SIZE, white, p->master_url); - y -= .05; + y -= .05f; snprintf(buf, sizeof(buf), "User: %s", p->user_name.c_str()); ttf_render_string(x, y, 0, PROJ_INFO_SIZE, white, buf); - y -= .05; + y -= .05f; if (p->team_name.size()) { snprintf(buf, sizeof(buf), "Team: %s", p->team_name.c_str()); ttf_render_string(x, y, 0, PROJ_INFO_SIZE, white, buf); - y -= .05; + y -= .05f; } snprintf(buf, sizeof(buf), "Total credit: %.0f Average credit: %.0f", p->user_total_credit, p->user_expavg_credit); ttf_render_string(x, y, 0, PROJ_INFO_SIZE, white, buf); - y -= .05; + y -= .05f; if (p->suspended_via_gui) { ttf_render_string(x, y, 0, PROJ_INFO_SIZE, white, "Suspended"); } } void show_disconnected() { - float x=.3, y=.3; + float x=.3f, y=.3f; char buf[256]; snprintf(buf, sizeof(buf), "%s is not running.", brand_name); ttf_render_string(x, y, 0, ALERT_SIZE, white, buf); } void show_no_projects() { - float x=.2, y=.3; + float x=.2f, y=.3f; char buf[256]; snprintf(buf, sizeof(buf), "%s is not attached to any projects.", brand_name); ttf_render_string(x, y, 0, ALERT_SIZE, white, buf); - y = .25; + y = .25f; snprintf(buf, sizeof(buf), "Attach to projects using %s.", brand_name); ttf_render_string(x, y, 0, ALERT_SIZE, white, buf); } @@ -271,7 +271,7 @@ void show_no_projects() { // index is where to start looking in job array // void show_jobs(unsigned int index, double alpha) { - float x=.1, y=.7; + float x=.1f, y=.7f; unsigned int nfound = 0; unsigned int i; cc_status.task_suspend_reason &= ~SUSPEND_REASON_CPU_THROTTLE; @@ -285,16 +285,16 @@ void show_jobs(unsigned int index, double alpha) { if (r->scheduler_state != CPU_SCHED_SCHEDULED) continue; if (!nfound) { ttf_render_string(x, y, 0, TASK_INTRO_SIZE, white, "Running tasks:"); - y -= .05; + y -= .05f; } show_result(r, x, y, alpha); - y -= .05; + y -= .05f; nfound++; if (nfound == MAX_JOBS_DISPLAY) break; } } if (!nfound) { - y = .5; + y = .5f; ttf_render_string(x, y, 0, TASK_NONE_SIZE, white, "No running tasks"); char *p = 0; switch (cc_status.task_suspend_reason) { @@ -324,7 +324,7 @@ void show_jobs(unsigned int index, double alpha) { p = "Computing suspended because processor usage is high"; break; } if (p) { - y -= .1; + y -= .1f; ttf_render_string(x, y, 0, TASK_NONE_REASON_SIZE, white, p); } } @@ -382,7 +382,7 @@ void app_graphics_render(int , int , double t) { double alpha; static bool showing_project = false; static unsigned int project_index = 0, job_index=0; - static float logo_pos[3] = {.2, .2, 0}; + static float logo_pos[3] = {.2f, .2f, 0}; int retval; if (!connected) { From 69c0d57c69ae10489b25f394bf18115272fecdf0 Mon Sep 17 00:00:00 2001 From: Vitalii Koshura Date: Tue, 10 Sep 2024 01:10:40 +0200 Subject: [PATCH 02/16] boinccmd: fix size_t -> int conversion and unreachable code warning Signed-off-by: Vitalii Koshura --- client/boinc_cmd.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/boinc_cmd.cpp b/client/boinc_cmd.cpp index 30250725ab5..93f2ec3cd27 100644 --- a/client/boinc_cmd.cpp +++ b/client/boinc_cmd.cpp @@ -122,7 +122,6 @@ char* next_arg(int argc, char** argv, int& i) { if (i >= argc) { fprintf(stderr, "Missing command-line argument\n"); usage(); - exit(1); } return argv[i++]; } @@ -212,7 +211,7 @@ void show_str_lists(vector &lines, size_t ncols) { for (const STR_LIST& s: lines) { max = std::max(max, strlen(s[i])); } - lengths.push_back(max); + lengths.push_back(static_cast(max)); } for (const STR_LIST &line : lines) { for (i=0; i Date: Tue, 10 Sep 2024 01:16:56 +0200 Subject: [PATCH 03/16] clientgui: fix deprecation warning by replacing outdated wxBOLD with wxFONTWEIGHT_BOLD macro Signed-off-by: Vitalii Koshura --- clientgui/common/wxPieCtrl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clientgui/common/wxPieCtrl.cpp b/clientgui/common/wxPieCtrl.cpp index 12d9e6deaad..271e25b9ade 100644 --- a/clientgui/common/wxPieCtrl.cpp +++ b/clientgui/common/wxPieCtrl.cpp @@ -63,7 +63,7 @@ wxPieCtrl::wxPieCtrl(wxWindow * parent, wxWindowID id, wxPoint pos, m_LabelColour = isDarkMode ? *wxWHITE : *wxBLACK; m_LegendBackColour = isDarkMode ? wxColour(0, 0, 255) : wxColour(255,255,0); m_TitleFont = *wxSWISS_FONT; - m_TitleFont.SetWeight(wxBOLD); + m_TitleFont.SetWeight(wxFONTWEIGHT_BOLD); m_LabelFont = *wxSWISS_FONT; m_legendHorBorder = 10; m_LegendVerBorder = 10; From 421bc875c5fac03b7ee11b4106ee385b4e3609f2 Mon Sep 17 00:00:00 2001 From: Vitalii Koshura Date: Tue, 10 Sep 2024 01:37:01 +0200 Subject: [PATCH 04/16] crypt_prog: fix warnings. - fix issue with variable shadowing - fix int <-> size_t conversion warning - fix size_t <-> unsigned int conversion warning Signed-off-by: Vitalii Koshura --- lib/crypt_prog.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/crypt_prog.cpp b/lib/crypt_prog.cpp index 5e4d5878b08..d9b872dd6a7 100644 --- a/lib/crypt_prog.cpp +++ b/lib/crypt_prog.cpp @@ -86,7 +86,7 @@ void usage() { } unsigned int random_int() { - unsigned int n; + unsigned int n = 0; #if defined(_WIN32) #if defined(__CYGWIN32__) HMODULE hLib=LoadLibrary((const char *)"ADVAPI32.DLL"); @@ -238,8 +238,8 @@ int main(int argc, char** argv) { if (retval) die("read_public_key"); f = fopen(argv[3], "r"); if (!f) die("fopen"); - int n = fread(cbuf, 1, 256, f); - cbuf[n] = 0; + size_t k = fread(cbuf, 1, 256, f); + cbuf[k] = 0; retval = check_string_signature(argv[2], cbuf, public_key, is_valid); if (retval) die("check_string_signature"); @@ -264,7 +264,7 @@ int main(int argc, char** argv) { if (retval) die("read_public_key"); strcpy((char*)buf2, "encryption test successful"); in.data = buf2; - in.len = strlen((char*)in.data); + in.len = static_cast(strlen((char*)in.data)); out.data = buf; encrypt_private(private_key, in, out); in = out; From a2b738ce2df94cc54514e256122a20d89106338c Mon Sep 17 00:00:00 2001 From: Vitalii Koshura Date: Tue, 10 Sep 2024 01:48:13 +0200 Subject: [PATCH 05/16] example_app: fix uninitialized variable warning Signed-off-by: Vitalii Koshura --- samples/example_app/uc2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/example_app/uc2.cpp b/samples/example_app/uc2.cpp index b2e2119714a..ae347d3729d 100644 --- a/samples/example_app/uc2.cpp +++ b/samples/example_app/uc2.cpp @@ -141,7 +141,7 @@ void update_shmem() { int main(int argc, char **argv) { int i; - int c, nchars = 0, retval, n; + int c, nchars = 0, retval, n = 0; double fsize, fd; char input_path[512], output_path[512], chkpt_path[512], buf[256]; MFILE out; From e721c05b03f9b6df6de82fb2574a29f8a9577f80 Mon Sep 17 00:00:00 2001 From: Vitalii Koshura Date: Tue, 10 Sep 2024 01:48:54 +0200 Subject: [PATCH 06/16] openclapp: fix shadowed variable warnings Signed-off-by: Vitalii Koshura --- samples/openclapp/openclapp.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/samples/openclapp/openclapp.cpp b/samples/openclapp/openclapp.cpp index afe6e51ab58..ed0b08e9d10 100644 --- a/samples/openclapp/openclapp.cpp +++ b/samples/openclapp/openclapp.cpp @@ -161,7 +161,7 @@ int main(int argc, char * argv[]) { print_to_file(&out,input,matrixSize); - for (int i=lastInversion+1;i<=NUM_ITERATIONS;++i) { + for (i=lastInversion+1;i<=NUM_ITERATIONS;++i) { //the invert function will trigger kernel calls. invert(input,output,matrixSize); printf("Finish inversion #%d\n",i); @@ -225,7 +225,7 @@ int main(int argc, char * argv[]) { if (cpu_time) { printf("\nBurning up some CPU time ... \n"); double start = dtime(); - for (int i=0; ; i++) { + for (i=0; ; i++) { double e = dtime()-start; if (e > cpu_time) break; fd = .5 + .5*(e/cpu_time); @@ -273,7 +273,7 @@ static double do_a_giga_flop(int foo) { } /* Save the computation state into checkpoint file */ -int do_checkpoint(MFILE& mf, int n, cl_float *input, int matrixSize) { +int do_checkpoint(MFILE& mf, int n, cl_float *in, int matrixSize) { int retval; string resolved_name; @@ -285,7 +285,7 @@ int do_checkpoint(MFILE& mf, int n, cl_float *input, int matrixSize) { fprintf(f, " "); for (int i=0;i Date: Tue, 10 Sep 2024 02:02:01 +0200 Subject: [PATCH 07/16] uc2_graphics: fix float <-> double conversion warnings Signed-off-by: Vitalii Koshura --- samples/example_app/uc2_graphics.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/samples/example_app/uc2_graphics.cpp b/samples/example_app/uc2_graphics.cpp index 72fa33ee775..6bdda532eca 100644 --- a/samples/example_app/uc2_graphics.cpp +++ b/samples/example_app/uc2_graphics.cpp @@ -61,7 +61,7 @@ APP_INIT_DATA uc_aid; bool mouse_down = false; int mouse_x, mouse_y; double pitch_angle, roll_angle, viewpoint_distance=10; -float color[4] = {.7, .2, .5, 1}; +float color[4] = {.7f, .2f, .5f, 1}; // the color of the 3D object. // Can be changed using preferences UC_SHMEM* shmem = NULL; @@ -79,15 +79,15 @@ static void init_lights() { static void draw_logo() { if (logo.present) { - float pos[3] = {.2, .3, 0}; - float size[3] = {.6, .4, 0}; + float pos[3] = {.2f, .3f, 0}; + float size[3] = {.6f, .4f, 0}; logo.draw(pos, size, ALIGN_CENTER, ALIGN_CENTER); } } static void draw_text() { static float x=0, y=0; - static float dx=0.0003, dy=0.0007; + static float dx=0.0003f, dy=0.0007f; char buf[256]; x += dx; y += dy; @@ -122,7 +122,7 @@ static void draw_text() { static void draw_3d_stuff() { static float x=0, y=0, z=10; - static float dx=0.3, dy=0.2, dz=0.5; + static float dx=0.3f, dy=0.2f, dz=0.5f; x += dx; y += dy; z += dz; From 2fe906588744cb47d3b1852a6d9141af9a3219b9 Mon Sep 17 00:00:00 2001 From: Vitalii Koshura Date: Tue, 10 Sep 2024 02:09:34 +0200 Subject: [PATCH 08/16] nvcuda: fix shadowed variable warnings Signed-off-by: Vitalii Koshura --- samples/nvcuda/cuda.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/nvcuda/cuda.cpp b/samples/nvcuda/cuda.cpp index abcc717f35d..c15a9b8125d 100644 --- a/samples/nvcuda/cuda.cpp +++ b/samples/nvcuda/cuda.cpp @@ -111,7 +111,7 @@ int main(int argc, char** argv) { printf("Last inversion # is : %d\n",lastInversion); fscanf(state,"%d",&dimension); cudaMallocHost((void **)&h_idata,dimension*dimension*sizeof(REAL)); - for (int i=0;i cpu_time) break; fd = .5 + .5*(e/cpu_time); From 3e3682ab3f85637b945d26327bcc9cd6840e6d91 Mon Sep 17 00:00:00 2001 From: Vitalii Koshura Date: Tue, 10 Sep 2024 02:15:39 +0200 Subject: [PATCH 09/16] sporadic: fix size_t <-> unsigned int conversion warning Signed-off-by: Vitalii Koshura --- samples/sporadic/sporadic.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/sporadic/sporadic.cpp b/samples/sporadic/sporadic.cpp index 6f29dabee35..2b259b228ca 100644 --- a/samples/sporadic/sporadic.cpp +++ b/samples/sporadic/sporadic.cpp @@ -49,7 +49,7 @@ void set_ac_state(SPORADIC_AC_STATE ac_state) { char buf[256]; sprintf(buf, "%d\n", ac_state); lseek(ac_fd, 0, SEEK_SET); - write(ac_fd, buf, strlen(buf)); + write(ac_fd, buf, static_cast(strlen(buf))); } last = ac_state; } else { From 70c95cdeafc071ae2ec689a25e5cc2426aca3b30 Mon Sep 17 00:00:00 2001 From: Vitalii Koshura Date: Tue, 10 Sep 2024 02:26:24 +0200 Subject: [PATCH 10/16] libgraphics: fix warnings - fix variable shadowing warnings - fix variable assignment in the condition expression warnings - fix my_error_mgr structure variables order to preserve space. Signed-off-by: Vitalii Koshura --- api/graphics2_win.cpp | 10 +++++----- api/gutil.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/graphics2_win.cpp b/api/graphics2_win.cpp index 63f29898e81..4cb1af4a3c5 100644 --- a/api/graphics2_win.cpp +++ b/api/graphics2_win.cpp @@ -71,7 +71,7 @@ void boinc_close_window_and_quit(const char* p) { } } -void SetupPixelFormat(HDC win_dc) { +void SetupPixelFormat(HDC dc) { int nPixelFormat; char buf[256]; @@ -98,11 +98,11 @@ void SetupPixelFormat(HDC win_dc) { // chooses the best pixel format // - nPixelFormat = ChoosePixelFormat(win_dc, &pfd); + nPixelFormat = ChoosePixelFormat(dc, &pfd); // set pixel format to device context. // - if (!SetPixelFormat(win_dc, nPixelFormat, &pfd)) { + if (!SetPixelFormat(dc, nPixelFormat, &pfd)) { fprintf(stderr, "%s ERROR: Couldn't set pixel format for device context (0x%x).\n", boinc_msg_prefix(buf, sizeof(buf)), GetLastError() @@ -468,14 +468,14 @@ void boinc_set_windows_icon(const char* icon16, const char* icon48) { LONGLONG ic; HWND hWnd = FindWindow("BOINC_app",NULL); - if (ic = (LONGLONG)LoadIcon(instance, icon48)) { + if ((ic = (LONGLONG)LoadIcon(instance, icon48)) != 0) { #ifdef _WIN64 SetClassLongPtr(hWnd, GCLP_HICON, (LONG_PTR)ic); #else SetClassLongPtr(hWnd, GCLP_HICON, (LONG)ic); #endif } - if (ic = (LONGLONG)LoadImage(instance, icon16, IMAGE_ICON, 16, 16, 0)) { + if ((ic = (LONGLONG)LoadImage(instance, icon16, IMAGE_ICON, 16, 16, 0)) != 0) { #ifdef _WIN64 SetClassLongPtr(hWnd, GCLP_HICONSM, (LONG_PTR)ic); #else diff --git a/api/gutil.cpp b/api/gutil.cpp index 6cd12099a58..ad4a5d8e8a6 100644 --- a/api/gutil.cpp +++ b/api/gutil.cpp @@ -626,8 +626,8 @@ void DecodeJPG(jpeg_decompress_struct* cinfo, tImageJPG *pImageData) { } struct my_error_mgr { - struct jpeg_error_mgr pub; jmp_buf setjmp_buffer; + struct jpeg_error_mgr pub; }; typedef struct my_error_mgr * my_error_ptr; From c682798f4eff8c5cb9887cccdb1bdd2eb6e60f31 Mon Sep 17 00:00:00 2001 From: Vitalii Koshura Date: Tue, 10 Sep 2024 02:33:19 +0200 Subject: [PATCH 11/16] slideshow: fix float <-> doube conversion warnings Signed-off-by: Vitalii Koshura --- samples/example_app/slide_show.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/example_app/slide_show.cpp b/samples/example_app/slide_show.cpp index 913388d8254..fc75f00f9d1 100644 --- a/samples/example_app/slide_show.cpp +++ b/samples/example_app/slide_show.cpp @@ -51,7 +51,7 @@ APP_INIT_DATA uc_aid; bool mouse_down = false; int mouse_x, mouse_y; double pitch_angle, roll_angle, viewpoint_distance=10; -float color[4] = {.7, .2, .5, 1}; +float color[4] = {.7f, .2f, .5f, 1}; // the color of the 3D object. // Can be changed using preferences UC_SHMEM* shmem = NULL; @@ -143,8 +143,8 @@ static void init_lights() { static void draw_logo() { if (logo.present) { - float pos[3] = {.2, .3, 0}; - float size[3] = {.6, .4, 0}; + float pos[3] = {.2f, .3f, 0}; + float size[3] = {.6f, .4f, 0}; logo.draw(pos, size, ALIGN_CENTER, ALIGN_CENTER); } } From c0f52701cea6152c0328ed94d11dc01358fc06e0 Mon Sep 17 00:00:00 2001 From: Vitalii Koshura Date: Tue, 10 Sep 2024 02:55:54 +0200 Subject: [PATCH 12/16] libboinc, unittests: change strcpy to strncpy and sprintf to snprintf Signed-off-by: Vitalii Koshura --- lib/common_defs.h | 2 +- tests/unit-tests/lib/test_parse.cpp | 2 +- tests/unit-tests/lib/test_str_util.cpp | 38 +++++++++++++------------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/common_defs.h b/lib/common_defs.h index c5cbcb6a71f..472cf4f96c4 100644 --- a/lib/common_defs.h +++ b/lib/common_defs.h @@ -395,7 +395,7 @@ struct DEVICE_STATUS { battery_temperature_celsius = 0; wifi_online = false; user_active = false; - strcpy(device_name, ""); + strncpy(device_name, "", sizeof(device_name)); } }; diff --git a/tests/unit-tests/lib/test_parse.cpp b/tests/unit-tests/lib/test_parse.cpp index a0134d5eab2..86b75a024da 100644 --- a/tests/unit-tests/lib/test_parse.cpp +++ b/tests/unit-tests/lib/test_parse.cpp @@ -85,7 +85,7 @@ namespace test_parse { int expects = 0; char name[64]; - strcpy(name, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); + strncpy(name, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", sizeof(name)); int val; diff --git a/tests/unit-tests/lib/test_str_util.cpp b/tests/unit-tests/lib/test_str_util.cpp index f50e572956c..e2d572eeafd 100644 --- a/tests/unit-tests/lib/test_str_util.cpp +++ b/tests/unit-tests/lib/test_str_util.cpp @@ -122,7 +122,7 @@ namespace test_str_util { char* argv[100]; int ret; char *nilbuf {0}; - sprintf(buf, "one two three"); + snprintf(buf, sizeof(buf), "one two three"); ret = parse_command_line(buf, argv); EXPECT_EQ(ret, 3); EXPECT_STREQ(argv[0], "one"); @@ -130,7 +130,7 @@ namespace test_str_util { EXPECT_STREQ(argv[2], "three"); EXPECT_STREQ(argv[3], nilbuf); EXPECT_STREQ(buf, "one"); - sprintf(buf, "four \'five\' \"six\""); + snprintf(buf, sizeof(buf), "four \'five\' \"six\""); ret = parse_command_line(buf, argv); EXPECT_EQ(ret, 3); EXPECT_STREQ(argv[0], "four"); @@ -138,7 +138,7 @@ namespace test_str_util { EXPECT_STREQ(argv[2], "six"); EXPECT_STREQ(argv[3], nilbuf); EXPECT_STREQ(buf, "four"); - sprintf(buf, "seven \'eig ht\' \"ni ne\""); + snprintf(buf, sizeof(buf), "seven \'eig ht\' \"ni ne\""); ret = parse_command_line(buf, argv); EXPECT_EQ(ret, 3); EXPECT_STREQ(argv[0], "seven"); @@ -146,7 +146,7 @@ namespace test_str_util { EXPECT_STREQ(argv[2], "ni ne"); EXPECT_STREQ(argv[3], nilbuf); EXPECT_STREQ(buf, "seven"); - sprintf(buf, "tän \'elèv én\' \"tŵelv e\""); + snprintf(buf, sizeof(buf), "tän \'elèv én\' \"tŵelv e\""); ret = parse_command_line(buf, argv); EXPECT_EQ(ret, 3); EXPECT_STREQ(argv[0], "tän"); @@ -155,7 +155,7 @@ namespace test_str_util { EXPECT_STREQ(argv[3], nilbuf); EXPECT_STREQ(buf, "tän"); // function doesn't check syntax so this works too - sprintf(buf, "13\" \'\"4teen\'\" "); + snprintf(buf, sizeof(buf), "13\" \'\"4teen\'\" "); ret = parse_command_line(buf, argv); EXPECT_EQ(ret, 3); EXPECT_STREQ(argv[0], "13\""); @@ -287,10 +287,10 @@ namespace test_str_util { char buf[256] = "_(\"The quick brown fox jumps over the lazy dog\")"; strip_translation(buf); EXPECT_STREQ(buf, "The quick brown fox jumps over the lazy dog"); - sprintf(buf, "The _(\"quick brown\") fox jumps over the _(\"lazy\") dog"); + snprintf(buf, sizeof(buf), "The _(\"quick brown\") fox jumps over the _(\"lazy\") dog"); strip_translation(buf); EXPECT_STREQ(buf, "The quick brown fox jumps over the lazy dog"); - sprintf(buf, "The _\"quick brown\" ) fox jumps over the (_\"lazy\") dog"); + snprintf(buf, sizeof(buf), "The _\"quick brown\" ) fox jumps over the (_\"lazy\") dog"); strip_translation(buf); EXPECT_STREQ(buf, "The _\"quick brown\" ) fox jumps over the (_\"lazy dog"); } @@ -298,10 +298,10 @@ namespace test_str_util { TEST_F(test_str_util, lf_terminate) { char *buf; buf = (char*)malloc(256); - strcpy(buf, "no\nlf ending"); + strncpy(buf, "no\nlf ending", sizeof(buf)); buf = lf_terminate(buf); EXPECT_STREQ(buf, "no\nlf ending\n"); - strcpy(buf, "lf\n ending\n"); + strncpy(buf, "lf\n ending\n", sizeof(buf)); buf = lf_terminate(buf); EXPECT_STREQ(buf, "lf\n ending\n"); } @@ -314,47 +314,47 @@ namespace test_str_util { EXPECT_STREQ(buf1, "[BOINC|1.2.3]"); EXPECT_STREQ(buf2, ""); EXPECT_STREQ(buf3, ""); - strcpy(buf, "[BOINC|1.2.3][vbox|4.5.6abc]"); + strncpy(buf, "[BOINC|1.2.3][vbox|4.5.6abc]", sizeof(buf)); parse_serialnum(buf, buf1, buf2, buf3); EXPECT_STREQ(buf1, "[BOINC|1.2.3]"); EXPECT_STREQ(buf2, "[vbox|4.5.6abc]"); EXPECT_STREQ(buf3, ""); - strcpy(buf, "[BOINC|1.2.3][INTEL|Intel(R) HD Graphics|1|2406MB||201]"); + strncpy(buf, "[BOINC|1.2.3][INTEL|Intel(R) HD Graphics|1|2406MB||201]", sizeof(buf)); parse_serialnum(buf, buf1, buf2, buf3); EXPECT_STREQ(buf1, "[BOINC|1.2.3]"); EXPECT_STREQ(buf2, ""); EXPECT_STREQ(buf3, "[INTEL|Intel(R) HD Graphics|1|2406MB||201]"); - strcpy(buf, "[vbox|4.5.6abc][INTEL|Intel(R) HD Graphics|1|2406MB||201][BOINC|1.2.3]"); + strncpy(buf, "[vbox|4.5.6abc][INTEL|Intel(R) HD Graphics|1|2406MB||201][BOINC|1.2.3]", sizeof(buf)); parse_serialnum(buf, buf1, buf2, buf3); EXPECT_STREQ(buf1, "[BOINC|1.2.3]"); EXPECT_STREQ(buf2, "[vbox|4.5.6abc]"); EXPECT_STREQ(buf3, "[INTEL|Intel(R) HD Graphics|1|2406MB||201]"); - strcpy(buf, "[BOINC|1.2.3][INTEL|Intel(R) HD Graphics|1|2406MB||201][vbox|4.5.6abc]"); + strncpy(buf, "[BOINC|1.2.3][INTEL|Intel(R) HD Graphics|1|2406MB||201][vbox|4.5.6abc]", sizeof(buf)); parse_serialnum(buf, buf1, buf2, buf3); EXPECT_STREQ(buf1, "[BOINC|1.2.3]"); EXPECT_STREQ(buf2, "[vbox|4.5.6abc]"); EXPECT_STREQ(buf3, "[INTEL|Intel(R) HD Graphics|1|2406MB||201]"); - strcpy(buf, "[BOINC|1.2.3][vbox|4.5.6abc][INTEL|Intel(R) HD Graphics|1|2406MB||201]"); + strncpy(buf, "[BOINC|1.2.3][vbox|4.5.6abc][INTEL|Intel(R) HD Graphics|1|2406MB||201]", sizeof(buf)); parse_serialnum(buf, buf1, buf2, buf3); EXPECT_STREQ(buf1, "[BOINC|1.2.3]"); EXPECT_STREQ(buf2, "[vbox|4.5.6abc]"); EXPECT_STREQ(buf3, "[INTEL|Intel(R) HD Graphics|1|2406MB||201]"); - strcpy(buf, "[BOINC|7.6.22][CAL|ATI Radeon HD 5800/5900 series (Cypress/Hemlock)|2|1024MB|1.4.1848|102][vbox|5.1.26]"); + strncpy(buf, "[BOINC|7.6.22][CAL|ATI Radeon HD 5800/5900 series (Cypress/Hemlock)|2|1024MB|1.4.1848|102][vbox|5.1.26]", sizeof(buf)); parse_serialnum(buf, buf1, buf2, buf3); EXPECT_STREQ(buf1, "[BOINC|7.6.22]"); EXPECT_STREQ(buf2, "[vbox|5.1.26]"); EXPECT_STREQ(buf3, "[CAL|ATI Radeon HD 5800/5900 series (Cypress/Hemlock)|2|1024MB|1.4.1848|102]"); - strcpy(buf, "[BOINC|7.6.22[CAL|ATI Radeon HD 5800/5900 series (Cypress/Hemlock)|2|1024MB|1.4.1848|102][vbox|5.1.26]"); + strncpy(buf, "[BOINC|7.6.22[CAL|ATI Radeon HD 5800/5900 series (Cypress/Hemlock)|2|1024MB|1.4.1848|102][vbox|5.1.26]", sizeof(buf)); parse_serialnum(buf, buf1, buf2, buf3); EXPECT_STREQ(buf1, "[BOINC|7.6.22[CAL|ATI Radeon HD 5800/5900 series (Cypress/Hemlock)|2|1024MB|1.4.1848|102]"); EXPECT_STREQ(buf2, "[vbox|5.1.26]"); EXPECT_STREQ(buf3, ""); - strcpy(buf, "[BOINC|7.6.22][CAL|ATI Radeon HD 5800/5900 series [Cypress/Hemlock]|2|1024MB|1.4.1848|102][vbox|5.1.26]"); + strncpy(buf, "[BOINC|7.6.22][CAL|ATI Radeon HD 5800/5900 series [Cypress/Hemlock]|2|1024MB|1.4.1848|102][vbox|5.1.26]", sizeof(buf)); parse_serialnum(buf, buf1, buf2, buf3); EXPECT_STREQ(buf1, "[BOINC|7.6.22]"); EXPECT_STREQ(buf2, ""); EXPECT_STREQ(buf3, "[CAL|ATI Radeon HD 5800/5900 series [Cypress/Hemlock]"); - strcpy(buf, "[BOINC|7.6.22][CAL|ATI Radeon HD 5800/5900 series (Cypress/Hemlock)|2|1024MB|1.4.1848|102][extra|7.8.9][vbox|5.1.26]"); + strncpy(buf, "[BOINC|7.6.22][CAL|ATI Radeon HD 5800/5900 series (Cypress/Hemlock)|2|1024MB|1.4.1848|102][extra|7.8.9][vbox|5.1.26]", sizeof(buf)); parse_serialnum(buf, buf1, buf2, buf3); EXPECT_STREQ(buf1, "[BOINC|7.6.22]"); EXPECT_STREQ(buf2, "[vbox|5.1.26]"); @@ -390,7 +390,7 @@ namespace test_str_util { EXPECT_STREQ(buf, "blah"); EXPECT_EQ(path_to_filename("hellokeith", buf), 0); EXPECT_STREQ(buf, "hellokeith"); - strcpy(buf, ""); + strncpy(buf, "", sizeof(buf)); EXPECT_EQ(path_to_filename("/home/blah/", buf), -2); EXPECT_STREQ(buf, ""); EXPECT_EQ(path_to_filename("", buf), -1); From b9d2992582eb52e7dfa7c24eca41abd762b79f6c Mon Sep 17 00:00:00 2001 From: Vitalii Koshura Date: Tue, 10 Sep 2024 03:16:47 +0200 Subject: [PATCH 13/16] slide_show, uc2_graphics, worker: hide unreferenced parameters Signed-off-by: Vitalii Koshura --- samples/example_app/slide_show.cpp | 9 +++------ samples/example_app/uc2_graphics.cpp | 6 +++--- samples/worker/worker.cpp | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/samples/example_app/slide_show.cpp b/samples/example_app/slide_show.cpp index fc75f00f9d1..2a76d12dc7c 100644 --- a/samples/example_app/slide_show.cpp +++ b/samples/example_app/slide_show.cpp @@ -177,7 +177,7 @@ static void init_camera(double dist) { set_viewpoint(dist); } -void app_graphics_render(int xs, int ys, double time_of_day) { +void app_graphics_render(int, int, double) { // boinc_graphics_get_shmem() must be called after // boinc_parse_init_data_file() // Put this in the main loop to allow retries if the @@ -212,12 +212,9 @@ void app_graphics_resize(int w, int h){ // mouse drag w/ left button rotates 3D objects; // mouse draw w/ right button zooms 3D objects // -void boinc_app_mouse_move(int x, int y, int left, int middle, int right) { +void boinc_app_mouse_move(int, int, int, int, int){} -} - -void boinc_app_mouse_button(int x, int y, int which, int is_down) { -} +void boinc_app_mouse_button(int, int, int, int){} void boinc_app_key_press(int, int){} diff --git a/samples/example_app/uc2_graphics.cpp b/samples/example_app/uc2_graphics.cpp index 6bdda532eca..c2c8acb3efb 100644 --- a/samples/example_app/uc2_graphics.cpp +++ b/samples/example_app/uc2_graphics.cpp @@ -165,7 +165,7 @@ static void init_camera(double dist) { set_viewpoint(dist); } -void app_graphics_render(int xs, int ys, double time_of_day) { +void app_graphics_render(int, int, double) { // boinc_graphics_get_shmem() must be called after // boinc_parse_init_data_file() // Put this in the main loop to allow retries if the @@ -211,7 +211,7 @@ void app_graphics_resize(int w, int h){ // mouse drag w/ left button rotates 3D objects; // mouse draw w/ right button zooms 3D objects // -void boinc_app_mouse_move(int x, int y, int left, int middle, int right) { +void boinc_app_mouse_move(int x, int y, int left, int, int right) { if (left) { pitch_angle += (y-mouse_y)*.1; roll_angle += (x-mouse_x)*.1; @@ -227,7 +227,7 @@ void boinc_app_mouse_move(int x, int y, int left, int middle, int right) { } } -void boinc_app_mouse_button(int x, int y, int which, int is_down) { +void boinc_app_mouse_button(int x, int y, int, int is_down) { if (is_down) { mouse_down = true; mouse_x = x; diff --git a/samples/worker/worker.cpp b/samples/worker/worker.cpp index dea13554299..77f591d56f8 100644 --- a/samples/worker/worker.cpp +++ b/samples/worker/worker.cpp @@ -165,7 +165,7 @@ int parse_command_line(char* p, char** argv) { return argc; } -int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR Args, int) { +int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { LPSTR command_line; char* argv[100]; int argc; From bd3b2a97e63284e9ed3af54a01b68a2f4bb0040d Mon Sep 17 00:00:00 2001 From: Vitalii Koshura Date: Tue, 10 Sep 2024 03:26:33 +0200 Subject: [PATCH 14/16] wrappture: hide unreferenced parameters, fix variable shadowing warning and int <-> UINT conversion warnings Signed-off-by: Vitalii Koshura --- samples/wrappture/wrappture.cpp | 6 +++--- samples/wrappture/wrappture_example.cpp | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/samples/wrappture/wrappture.cpp b/samples/wrappture/wrappture.cpp index 291ac5651b8..654c3ec186e 100644 --- a/samples/wrappture/wrappture.cpp +++ b/samples/wrappture/wrappture.cpp @@ -338,7 +338,7 @@ bool TASK::poll(int& status) { void TASK::kill() { #ifdef _WIN32 - TerminateProcess(pid_handle, -1); + TerminateProcess(pid_handle, static_cast(-1)); #else ::kill(pid, SIGKILL); #endif @@ -408,12 +408,12 @@ double TASK::cpu_time() { } void send_status_message( - TASK& task, double frac_done, double checkpoint_cpu_time + TASK& task, double frac_done, double checkpoint_cpu_time_value ) { double current_cpu_time = task.starting_cpu + task.cpu_time(); boinc_report_app_status( current_cpu_time, - checkpoint_cpu_time, + checkpoint_cpu_time_value, frac_done ); } diff --git a/samples/wrappture/wrappture_example.cpp b/samples/wrappture/wrappture_example.cpp index 69f6c77e9df..69bc7a58464 100644 --- a/samples/wrappture/wrappture_example.cpp +++ b/samples/wrappture/wrappture_example.cpp @@ -26,7 +26,7 @@ #include "filesys.h" #include "wrappture.h" -int main(int argc, char * argv[]) { +int main(int, char**) { char buf[256]; RpLibrary* lib = NULL; @@ -40,7 +40,6 @@ int main(int argc, char * argv[]) { double kT = 0.0; double Emin = 0.0; double Emax = 0.0; - double f = 0.0; int err = 0; @@ -119,7 +118,7 @@ int main(int argc, char * argv[]) { #ifdef _WIN32 -int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR Args, int WinMode) { +int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { LPSTR command_line; char* argv[100]; int argc; From 1ad881d97d25260ad0fd435ff4c0073a3ea1867c Mon Sep 17 00:00:00 2001 From: Vitalii Koshura Date: Tue, 10 Sep 2024 03:43:10 +0200 Subject: [PATCH 15/16] fix unittests Signed-off-by: Vitalii Koshura --- tests/unit-tests/lib/test_str_util.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/unit-tests/lib/test_str_util.cpp b/tests/unit-tests/lib/test_str_util.cpp index e2d572eeafd..34882c1e035 100644 --- a/tests/unit-tests/lib/test_str_util.cpp +++ b/tests/unit-tests/lib/test_str_util.cpp @@ -297,11 +297,12 @@ namespace test_str_util { TEST_F(test_str_util, lf_terminate) { char *buf; - buf = (char*)malloc(256); - strncpy(buf, "no\nlf ending", sizeof(buf)); + const size_t buf_size = 256; + buf = (char*)malloc(buf_size); + strncpy(buf, "no\nlf ending", buf_size); buf = lf_terminate(buf); EXPECT_STREQ(buf, "no\nlf ending\n"); - strncpy(buf, "lf\n ending\n", sizeof(buf)); + strncpy(buf, "lf\n ending\n", buf_size); buf = lf_terminate(buf); EXPECT_STREQ(buf, "lf\n ending\n"); } @@ -390,7 +391,7 @@ namespace test_str_util { EXPECT_STREQ(buf, "blah"); EXPECT_EQ(path_to_filename("hellokeith", buf), 0); EXPECT_STREQ(buf, "hellokeith"); - strncpy(buf, "", sizeof(buf)); + strncpy(buf, "", 2); EXPECT_EQ(path_to_filename("/home/blah/", buf), -2); EXPECT_STREQ(buf, ""); EXPECT_EQ(path_to_filename("", buf), -1); From 3be93daff3d8ed103d22829249ece9ae0df441e7 Mon Sep 17 00:00:00 2001 From: Vitalii Koshura Date: Tue, 10 Sep 2024 04:11:47 +0200 Subject: [PATCH 16/16] unittests: revert some changes to fix unit tests Signed-off-by: Vitalii Koshura --- tests/unit-tests/lib/test_str_util.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/unit-tests/lib/test_str_util.cpp b/tests/unit-tests/lib/test_str_util.cpp index 34882c1e035..67c288944dd 100644 --- a/tests/unit-tests/lib/test_str_util.cpp +++ b/tests/unit-tests/lib/test_str_util.cpp @@ -297,12 +297,11 @@ namespace test_str_util { TEST_F(test_str_util, lf_terminate) { char *buf; - const size_t buf_size = 256; - buf = (char*)malloc(buf_size); - strncpy(buf, "no\nlf ending", buf_size); + buf = (char*)malloc(256); + strcpy(buf, "no\nlf ending"); buf = lf_terminate(buf); EXPECT_STREQ(buf, "no\nlf ending\n"); - strncpy(buf, "lf\n ending\n", buf_size); + strcpy(buf, "lf\n ending\n"); buf = lf_terminate(buf); EXPECT_STREQ(buf, "lf\n ending\n"); } @@ -391,7 +390,7 @@ namespace test_str_util { EXPECT_STREQ(buf, "blah"); EXPECT_EQ(path_to_filename("hellokeith", buf), 0); EXPECT_STREQ(buf, "hellokeith"); - strncpy(buf, "", 2); + strcpy(buf, ""); EXPECT_EQ(path_to_filename("/home/blah/", buf), -2); EXPECT_STREQ(buf, ""); EXPECT_EQ(path_to_filename("", buf), -1);