From 6d0c561a0b1d3f3a5ad9cd9127aee372011b93cf Mon Sep 17 00:00:00 2001 From: Teemu Toivola Date: Sat, 13 Oct 2018 00:23:59 +0300 Subject: [PATCH] fix clang warnings --- CHANGES | 2 + src/image.c | 2 +- tests/image_tests.c | 130 ++++++++++++++++++++++---------------------- 3 files changed, 68 insertions(+), 66 deletions(-) diff --git a/CHANGES b/CHANGES index f04f70a..79efe9d 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,8 @@ - Fixed - Data rate calculations when using SI decimal prefixes + - Workaround for filled arcs not drawn correctly with some versions + of libgd (libgd/libgd#351) - New - C struct dump database has been replaced with sqlite database, full data import included from legacy databases of versions 1.3 - 1.18 diff --git a/src/image.c b/src/image.c index a3bb23e..80de9ae 100644 --- a/src/image.c +++ b/src/image.c @@ -256,7 +256,7 @@ void drawdonut(IMAGECONTENT *ic, const int x, const int y, const float rxp, cons if (rxarc) { gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270+txarc, 270+txarc+rxarc, ic->crxd, gdEdged|gdNoFill); if (rxarc >= 5) { - gdImageFill(ic->im, x+(DOUTRAD/2-3)*cos(((270*2+2*txarc+rxarc)/2)*M_PI/180), y+(DOUTRAD/2-3)*sin(((270*2+2*txarc+rxarc)/2)*M_PI/180), ic->crx); + gdImageFill(ic->im, (int)(x+(DOUTRAD/2-3)*cos(((270*2+2*txarc+rxarc)/2)*M_PI/180)), (int)(y+(DOUTRAD/2-3)*sin(((270*2+2*txarc+rxarc)/2)*M_PI/180)), ic->crx); } gdImageFilledArc(ic->im, x, y, DINRAD, DINRAD, 270+txarc, 270+txarc+rxarc, ic->crxd, gdEdged|gdNoFill); } diff --git a/tests/image_tests.c b/tests/image_tests.c index e54a190..4bbe3ce 100644 --- a/tests/image_tests.c +++ b/tests/image_tests.c @@ -413,7 +413,7 @@ START_TEST(output_check) initimagecontent(&ic); ic.im = gdImageCreate(x, y); colorinit(&ic); - ic.interface.updated = get_timestamp(2001, 2, 3, 4, 5); + ic.interface.updated = (time_t)get_timestamp(2001, 2, 3, 4, 5); layoutinit(&ic, "vnstati output reference test", x, y); pngout = fopen("vnstati_check.png", "w"); @@ -425,170 +425,170 @@ START_TEST(output_check) x = 40; y = 80; gdImageStringUp(ic.im, gdFontGetSmall(), 1, y+105, (unsigned char*)"libgd bug workaround", ic.ctext); - drawdonut(&ic, x, y, 0, 0); - drawdonut(&ic, x+55, y, 50.0, 50.0); + drawdonut(&ic, x, y, (float)0, (float)0); + drawdonut(&ic, x+55, y, (float)50, (float)50); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"0/0 - 50/50", ic.ctext); x += 130; - drawdonut(&ic, x, y, 100.0, 0); - drawdonut(&ic, x+55, y, 0, 100.0); + drawdonut(&ic, x, y, (float)100, (float)0); + drawdonut(&ic, x+55, y, (float)0, (float)100); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"100/0 - 0/100", ic.ctext); x += 130; - drawdonut(&ic, x, y, 60.0, 40.0); - drawdonut(&ic, x+55, y, 40.0, 60.0); + drawdonut(&ic, x, y, (float)60, (float)40); + drawdonut(&ic, x+55, y, (float)40, (float)60); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"60/40 - 40/60", ic.ctext); x += 130; - drawdonut(&ic, x, y, 75.0, 25.0); - drawdonut(&ic, x+55, y, 25.0, 75.0); + drawdonut(&ic, x, y, (float)75, (float)25); + drawdonut(&ic, x+55, y, (float)25, (float)75); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"75/25 - 25/75", ic.ctext); x += 130; - drawdonut(&ic, x, y, 90.0, 10.0); - drawdonut(&ic, x+55, y, 10.0, 90.0); + drawdonut(&ic, x, y, (float)90, (float)10); + drawdonut(&ic, x+55, y, (float)10, (float)90); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"90/10 - 10/90", ic.ctext); x += 130; - drawdonut(&ic, x, y, 95.0, 5.0); - drawdonut(&ic, x+55, y, 5.0, 95.0); + drawdonut(&ic, x, y, (float)95, (float)5); + drawdonut(&ic, x+55, y, (float)5, (float)95); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"95/5 - 5/95", ic.ctext); x += 130; - drawdonut(&ic, x, y, 99.0, 1.0); - drawdonut(&ic, x+55, y, 1.0, 99.0); + drawdonut(&ic, x, y, (float)99, (float)1); + drawdonut(&ic, x+55, y, (float)1, (float)99); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"99/1 - 1/99", ic.ctext); x += 130; - drawdonut(&ic, x, y, 99.9, 0.1); - drawdonut(&ic, x+55, y, 0.1, 99.9); + drawdonut(&ic, x, y, (float)99.9, (float)0.1); + drawdonut(&ic, x+55, y, (float)0.1, (float)99.9); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"99.9/0.1 - 0.1/99.9", ic.ctext); /* line 2 */ x = 40; y = 160; - drawdonut(&ic, x, y, 0, 0); - drawdonut(&ic, x+55, y, 25.0, 25.0); + drawdonut(&ic, x, y, (float)0, (float)0); + drawdonut(&ic, x+55, y, (float)25, (float)25); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"0/0 - 25/25", ic.ctext); x += 130; - drawdonut(&ic, x, y, 50.0, 0); - drawdonut(&ic, x+55, y, 0, 50.0); + drawdonut(&ic, x, y, (float)50, (float)0); + drawdonut(&ic, x+55, y, (float)0, (float)50); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"50/0 - 0/50", ic.ctext); x += 130; - drawdonut(&ic, x, y, 40.0, 30.0); - drawdonut(&ic, x+55, y, 30.0, 40.0); + drawdonut(&ic, x, y, (float)40, (float)30); + drawdonut(&ic, x+55, y, (float)30, (float)40); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"40/30 - 30/40", ic.ctext); x += 130; - drawdonut(&ic, x, y, 30.0, 20.0); - drawdonut(&ic, x+55, y, 20.0, 30.0); + drawdonut(&ic, x, y, (float)30, (float)20); + drawdonut(&ic, x+55, y, (float)20, (float)30); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"30/20 - 20/30", ic.ctext); x += 130; - drawdonut(&ic, x, y, 20.0, 10.0); - drawdonut(&ic, x+55, y, 10.0, 20.0); + drawdonut(&ic, x, y, (float)20, (float)10); + drawdonut(&ic, x+55, y, (float)10, (float)20); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"20/10 - 10/20", ic.ctext); x += 130; - drawdonut(&ic, x, y, 15.0, 5.0); - drawdonut(&ic, x+55, y, 5.0, 15.0); + drawdonut(&ic, x, y, (float)15, (float)5); + drawdonut(&ic, x+55, y, (float)5, (float)15); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"15/5 - 5/15", ic.ctext); x += 130; - drawdonut(&ic, x, y, 10.0, 1.0); - drawdonut(&ic, x+55, y, 1.0, 10.0); + drawdonut(&ic, x, y, (float)10, (float)1); + drawdonut(&ic, x+55, y, (float)1, (float)10); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"10/1 - 1/10", ic.ctext); x += 130; - drawdonut(&ic, x, y, 1.0, 0.1); - drawdonut(&ic, x+55, y, 0.1, 1.0); + drawdonut(&ic, x, y, (float)1, (float)0.1); + drawdonut(&ic, x+55, y, (float)0.1, (float)1); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"1.0/0.1 - 0.1/1.0", ic.ctext); /* line 3 */ x = 40; y = 270; gdImageStringUp(ic.im, gdFontGetSmall(), 1, y+105, (unsigned char*)"libgd native", ic.ctext); - drawdonut_libgd_native(&ic, x, y, 0, 0); - drawdonut_libgd_native(&ic, x+55, y, 50.0, 50.0); + drawdonut_libgd_native(&ic, x, y, (float)0, (float)0); + drawdonut_libgd_native(&ic, x+55, y, (float)50, (float)50); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"0/0 - 50/50", ic.ctext); x += 130; - drawdonut_libgd_native(&ic, x, y, 100.0, 0); - drawdonut_libgd_native(&ic, x+55, y, 0, 100.0); + drawdonut_libgd_native(&ic, x, y, (float)100, (float)0); + drawdonut_libgd_native(&ic, x+55, y, (float)0, (float)100); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"100/0 - 0/100", ic.ctext); x += 130; - drawdonut_libgd_native(&ic, x, y, 60.0, 40.0); - drawdonut_libgd_native(&ic, x+55, y, 40.0, 60.0); + drawdonut_libgd_native(&ic, x, y, (float)60, (float)40); + drawdonut_libgd_native(&ic, x+55, y, (float)40, (float)60); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"60/40 - 40/60", ic.ctext); x += 130; - drawdonut_libgd_native(&ic, x, y, 75.0, 25.0); - drawdonut_libgd_native(&ic, x+55, y, 25.0, 75.0); + drawdonut_libgd_native(&ic, x, y, (float)75, (float)25); + drawdonut_libgd_native(&ic, x+55, y, (float)25, (float)75); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"75/25 - 25/75", ic.ctext); x += 130; - drawdonut_libgd_native(&ic, x, y, 90.0, 10.0); - drawdonut_libgd_native(&ic, x+55, y, 10.0, 90.0); + drawdonut_libgd_native(&ic, x, y, (float)90, (float)10); + drawdonut_libgd_native(&ic, x+55, y, (float)10, (float)90); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"90/10 - 10/90", ic.ctext); x += 130; - drawdonut_libgd_native(&ic, x, y, 95.0, 5.0); - drawdonut_libgd_native(&ic, x+55, y, 5.0, 95.0); + drawdonut_libgd_native(&ic, x, y, (float)95, (float)5); + drawdonut_libgd_native(&ic, x+55, y, (float)5, (float)95); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"95/5 - 5/95", ic.ctext); x += 130; - drawdonut_libgd_native(&ic, x, y, 99.0, 1.0); - drawdonut_libgd_native(&ic, x+55, y, 1.0, 99.0); + drawdonut_libgd_native(&ic, x, y, (float)99, (float)1); + drawdonut_libgd_native(&ic, x+55, y, (float)1, (float)99); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"99/1 - 1/99", ic.ctext); x += 130; - drawdonut_libgd_native(&ic, x, y, 99.9, 0.1); - drawdonut_libgd_native(&ic, x+55, y, 0.1, 99.9); + drawdonut_libgd_native(&ic, x, y, (float)99.9, (float)0.1); + drawdonut_libgd_native(&ic, x+55, y, (float)0.1, (float)99.9); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"99.9/0.1 - 0.1/99.9", ic.ctext); /* line 4 */ x = 40; y = 350; - drawdonut_libgd_native(&ic, x, y, 0, 0); - drawdonut_libgd_native(&ic, x+55, y, 25.0, 25.0); + drawdonut_libgd_native(&ic, x, y, (float)0, (float)0); + drawdonut_libgd_native(&ic, x+55, y, (float)25, (float)25); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"0/0 - 25/25", ic.ctext); x += 130; - drawdonut_libgd_native(&ic, x, y, 50.0, 0); - drawdonut_libgd_native(&ic, x+55, y, 0, 50.0); + drawdonut_libgd_native(&ic, x, y, (float)50, (float)0); + drawdonut_libgd_native(&ic, x+55, y, (float)0, (float)50); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"50/0 - 0/50", ic.ctext); x += 130; - drawdonut_libgd_native(&ic, x, y, 40.0, 30.0); - drawdonut_libgd_native(&ic, x+55, y, 30.0, 40.0); + drawdonut_libgd_native(&ic, x, y, (float)40, (float)30); + drawdonut_libgd_native(&ic, x+55, y, (float)30, (float)40); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"40/30 - 30/40", ic.ctext); x += 130; - drawdonut_libgd_native(&ic, x, y, 30.0, 20.0); - drawdonut_libgd_native(&ic, x+55, y, 20.0, 30.0); + drawdonut_libgd_native(&ic, x, y, (float)30, (float)20); + drawdonut_libgd_native(&ic, x+55, y, (float)20, (float)30); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"30/20 - 20/30", ic.ctext); x += 130; - drawdonut_libgd_native(&ic, x, y, 20.0, 10.0); - drawdonut_libgd_native(&ic, x+55, y, 10.0, 20.0); + drawdonut_libgd_native(&ic, x, y, (float)20, (float)10); + drawdonut_libgd_native(&ic, x+55, y, (float)10, (float)20); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"20/10 - 10/20", ic.ctext); x += 130; - drawdonut_libgd_native(&ic, x, y, 15.0, 5.0); - drawdonut_libgd_native(&ic, x+55, y, 5.0, 15.0); + drawdonut_libgd_native(&ic, x, y, (float)15, (float)5); + drawdonut_libgd_native(&ic, x+55, y, (float)5, (float)15); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"15/5 - 5/15", ic.ctext); x += 130; - drawdonut_libgd_native(&ic, x, y, 10.0, 1.0); - drawdonut_libgd_native(&ic, x+55, y, 1.0, 10.0); + drawdonut_libgd_native(&ic, x, y, (float)10, (float)1); + drawdonut_libgd_native(&ic, x+55, y, (float)1, (float)10); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"10/1 - 1/10", ic.ctext); x += 130; - drawdonut_libgd_native(&ic, x, y, 1.0, 0.1); - drawdonut_libgd_native(&ic, x+55, y, 0.1, 1.0); + drawdonut_libgd_native(&ic, x, y, (float)1, (float)0.1); + drawdonut_libgd_native(&ic, x+55, y, (float)0.1, (float)1); gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"1.0/0.1 - 0.1/1.0", ic.ctext); -- 2.40.0