diff options
author | João Valverde <joao.valverde@tecnico.ulisboa.pt> | 2016-02-07 21:35:31 +0000 |
---|---|---|
committer | João Valverde <j@v6e.pt> | 2016-02-07 23:22:11 +0000 |
commit | d762a895ab570680e4e72142a348ad2b07c97d4f (patch) | |
tree | 896a9f000985ff01e896735930be9f5eb3350109 | |
parent | 847a713d12f9e39cd3f07b52ac8d77814e90c3db (diff) |
GTK: Check if lrint() is usable, fix warnings [-Wbad-function-cast]
Change-Id: I4714ba6cfbd18847d99650f5c5cdc60dd2e7af26
Reviewed-on: https://code.wireshark.org/review/13808
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: João Valverde <j@v6e.pt>
-rw-r--r-- | ConfigureChecks.cmake | 1 | ||||
-rw-r--r-- | cmakeconfig.h.in | 3 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | ui/gtk/rlc_lte_graph.c | 64 | ||||
-rw-r--r-- | ui/gtk/tcp_graph.c | 68 |
5 files changed, 76 insertions, 62 deletions
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index d9d3ca8efb..b30274310e 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -100,6 +100,7 @@ cmake_push_check_state() set(CMAKE_REQUIRED_INCLUDES ${M_INCLUDE_DIRS}) set(CMAKE_REQUIRED_LIBRARIES ${M_LIBRARIES}) check_symbol_exists("floorl" "math.h" HAVE_FLOORL) +check_symbol_exists("lrint" "math.h" HAVE_LRINT) cmake_pop_check_state() check_function_exists("getaddrinfo" HAVE_GETADDRINFO) diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index 778049a1c8..bff142b520 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -73,6 +73,9 @@ /* Define if you have the 'floorl' function. */ #cmakedefine HAVE_FLOORL 1 +/* Define if you have the 'lrint' function. */ +#cmakedefine HAVE_LRINT 1 + /* Define to 1 if you have the `getaddrinfo' function. */ #cmakedefine HAVE_GETADDRINFO 1 diff --git a/configure.ac b/configure.ac index 3b346a8786..65a6873ada 100644 --- a/configure.ac +++ b/configure.ac @@ -538,6 +538,8 @@ AC_SEARCH_LIBS(floorl, m, ], FLOORL_LO="floorl.lo") AC_SUBST(FLOORL_LO) +AC_SEARCH_LIBS(lrint, m, + [AC_DEFINE(HAVE_LRINT, 1, [Define if you have the 'lrint' function.])]) # diff --git a/ui/gtk/rlc_lte_graph.c b/ui/gtk/rlc_lte_graph.c index efb314693f..4d8ae51280 100644 --- a/ui/gtk/rlc_lte_graph.c +++ b/ui/gtk/rlc_lte_graph.c @@ -51,6 +51,10 @@ #include "ui/gtk/old-gtk-compat.h" +#ifndef HAVE_LRINT +#define lrint rint +#endif + #define AXIS_HORIZONTAL 0 #define AXIS_VERTICAL 1 @@ -959,10 +963,10 @@ static void draw_element_line(struct gtk_rlc_graph *g, struct element *e, cairo_ } /* Map point into graph area, and round to nearest int */ - xx1 = (int)rint(e->p.line.dim.x1 + g->geom.x - g->wp.x); - xx2 = (int)rint(e->p.line.dim.x2 + g->geom.x - g->wp.x); - yy1 = (int)rint((g->geom.height-1-e->p.line.dim.y1) + g->geom.y-g->wp.y); - yy2 = (int)rint((g->geom.height-1-e->p.line.dim.y2) + g->geom.y-g->wp.y); + xx1 = (int)lrint(e->p.line.dim.x1 + g->geom.x - g->wp.x); + xx2 = (int)lrint(e->p.line.dim.x2 + g->geom.x - g->wp.x); + yy1 = (int)lrint((g->geom.height-1-e->p.line.dim.y1) + g->geom.y-g->wp.y); + yy2 = (int)lrint((g->geom.height-1-e->p.line.dim.y2) + g->geom.y-g->wp.y); /* If line completely out of the area, we won't show it */ if (((xx1 < 0) && (xx2 < 0)) || ((xx1 >= g->wp.width) && (xx2 >= g->wp.width)) || @@ -1122,7 +1126,7 @@ static void v_axis_pixmap_draw(struct axis *axis) for (i=imin; i <= imax; i++) { gint w, h; char desc[32]; - int y = (int) (g->geom.height-1 - (int )rint(i * major_tick) - + int y = (int) (g->geom.height-1 - (int )lrint(i * major_tick) - offset + corr + axis->s.y); debug(DBS_AXES_DRAWING) printf("%f @ %d\n", @@ -1147,7 +1151,7 @@ static void v_axis_pixmap_draw(struct axis *axis) imin = (int) ((g->geom.height - offset + corr - g->wp.height)/minor_tick + 1); imax = (int) ((g->geom.height - offset + corr) / minor_tick); for (i=imin; i <= imax; i++) { - int y = (int) (g->geom.height-1 - (int )rint(i*minor_tick) - + int y = (int) (g->geom.height-1 - (int )lrint(i*minor_tick) - offset + corr + axis->s.y); if ((y > 0) && (y < axis->p.height)) { @@ -1503,18 +1507,18 @@ static int line_detect_collision(struct element *e, int x, int y) /* Get sorted x, y co-ordinates for line */ if (e->p.line.dim.x1 < e->p.line.dim.x2) { - xx1 = (int)rint(e->p.line.dim.x1); - xx2 = (int)rint(e->p.line.dim.x2); + xx1 = (int)lrint(e->p.line.dim.x1); + xx2 = (int)lrint(e->p.line.dim.x2); } else { - xx1 = (int)rint(e->p.line.dim.x2); - xx2 = (int)rint(e->p.line.dim.x1); + xx1 = (int)lrint(e->p.line.dim.x2); + xx2 = (int)lrint(e->p.line.dim.x1); } if (e->p.line.dim.y1 < e->p.line.dim.y2) { - yy1 = (int)rint(e->p.line.dim.y1); - yy2 = (int)rint(e->p.line.dim.y2); + yy1 = (int)lrint(e->p.line.dim.y1); + yy2 = (int)lrint(e->p.line.dim.y2); } else { - yy1 = (int)rint(e->p.line.dim.y2); - yy2 = (int)rint(e->p.line.dim.y1); + yy1 = (int)lrint(e->p.line.dim.y2); + yy2 = (int)lrint(e->p.line.dim.y1); } /* printf("line: (%d,%d)->(%d,%d), clicked: (%d,%d)\n", xx1, yy1, xx2, yy2, x, y); @@ -1534,10 +1538,10 @@ static int ellipse_detect_collision(struct element *e, int x, int y) { int xx1, yy1, xx2, yy2; - xx1 = (int )rint (e->p.ellipse.dim.x); - xx2 = (int )rint (e->p.ellipse.dim.x + e->p.ellipse.dim.width); - yy1 = (int )rint (e->p.ellipse.dim.y - e->p.ellipse.dim.height); - yy2 = (int )rint (e->p.ellipse.dim.y); + xx1 = (int )lrint (e->p.ellipse.dim.x); + xx2 = (int )lrint (e->p.ellipse.dim.x + e->p.ellipse.dim.width); + yy1 = (int )lrint (e->p.ellipse.dim.y - e->p.ellipse.dim.height); + yy2 = (int )lrint (e->p.ellipse.dim.y); /* printf ("ellipse: (%d,%d)->(%d,%d), clicked: (%d,%d)\n", xx1, yy1, xx2, yy2, x, y); */ @@ -1573,8 +1577,8 @@ static gboolean configure_event(GtkWidget *widget _U_, GdkEventConfigure *event, new_zoom.y = (double)g->wp.height / cur_wp_height; cur_g_width = g->geom.width; cur_g_height = g->geom.height; - g->geom.width = (int)rint(g->geom.width * new_zoom.x); - g->geom.height = (int)rint(g->geom.height * new_zoom.y); + g->geom.width = (int)lrint(g->geom.width * new_zoom.x); + g->geom.height = (int)lrint(g->geom.height * new_zoom.y); g->zoom.x = (double)(g->geom.width - 1) / g->bounds.width; g->zoom.y = (double)(g->geom.height -1) / g->bounds.height; @@ -1674,8 +1678,8 @@ perform_zoom(struct gtk_rlc_graph *g, struct zoomfactor *zf, int cur_width = g->geom.width, cur_height = g->geom.height; /* Multiply by x and y factors */ - g->geom.width = (int )rint(g->geom.width * zf->x); - g->geom.height = (int )rint(g->geom.height * zf->y); + g->geom.width = (int )lrint(g->geom.width * zf->x); + g->geom.height = (int )lrint(g->geom.height * zf->y); /* If already fully-zoomed out, don't waste time re-drawing */ if ((g->geom.width <= g->wp.width) && @@ -1696,9 +1700,9 @@ perform_zoom(struct gtk_rlc_graph *g, struct zoomfactor *zf, g->zoom.y = (g->geom.height- 1) / g->bounds.height; /* Move origin to keep mouse position at centre of view */ - g->geom.x -= (int)rint((g->geom.width - cur_width) * + g->geom.x -= (int)lrint((g->geom.width - cur_width) * ((origin_x - g->geom.x)/(double )cur_width)); - g->geom.y -= (int)rint((g->geom.height - cur_height) * + g->geom.y -= (int)lrint((g->geom.height - cur_height) * ((origin_y - g->geom.y)/(double )cur_height)); /* Again, don't go out of bounds */ @@ -1869,8 +1873,8 @@ static void do_zoom_common(struct gtk_rlc_graph *g, GdkEventButton *event, } /* Multiply by x and y factors */ - g->geom.width = (int )rint(g->geom.width * factor.x); - g->geom.height = (int )rint(g->geom.height * factor.y); + g->geom.width = (int )lrint(g->geom.width * factor.x); + g->geom.height = (int )lrint(g->geom.height * factor.y); /* Clip to space if necessary */ if (g->geom.width < g->wp.width) @@ -1883,9 +1887,9 @@ static void do_zoom_common(struct gtk_rlc_graph *g, GdkEventButton *event, g->zoom.y = (g->geom.height- 1) / g->bounds.height; /* Move origin to keep mouse position at centre of view */ - g->geom.x -= (int )rint((g->geom.width - cur_width) * + g->geom.x -= (int )lrint((g->geom.width - cur_width) * ((pointer_x - g->geom.x)/(double)cur_width)); - g->geom.y -= (int )rint((g->geom.height - cur_height) * + g->geom.y -= (int )lrint((g->geom.height - cur_height) * ((pointer_y - g->geom.y)/(double)cur_height)); /* Make sure we haven't moved outside the whole graph */ @@ -2006,8 +2010,8 @@ static gboolean button_press_event(GtkWidget *widget _U_, GdkEventButton *event, if (event->button == MOUSE_BUTTON_RIGHT) { /* Turn on grab. N.B. using (maybe) approx mouse position from event... */ - g->grab.x = (int )rint (event->x) - g->geom.x; - g->grab.y = (int )rint (event->y) - g->geom.y; + g->grab.x = (int )lrint (event->x) - g->geom.x; + g->grab.y = (int )lrint (event->y) - g->geom.y; g->grab.grabbed = TRUE; } else if (event->button == MOUSE_BUTTON_MIDDLE) { do_zoom_mouse(g, event); diff --git a/ui/gtk/tcp_graph.c b/ui/gtk/tcp_graph.c index c49540415c..37386a667f 100644 --- a/ui/gtk/tcp_graph.c +++ b/ui/gtk/tcp_graph.c @@ -55,6 +55,10 @@ #include "ui/gtk/old-gtk-compat.h" +#ifndef HAVE_LRINT +#define lrint rint +#endif + #define TCP_SYN(flags) ( flags & TH_SYN ) #define TCP_ACK(flags) ( flags & TH_ACK ) #define TCP_FIN(flags) ( flags & TH_FIN ) @@ -2020,10 +2024,10 @@ static void draw_element_line(struct gtk_graph *g, struct element *e, cairo_t *c gdk_cairo_set_source_rgba(cr, new_color); } - xx1 = (int )rint(e->p.line.dim.x1 + g->geom.x - g->wp.x); - xx2 = (int )rint(e->p.line.dim.x2 + g->geom.x - g->wp.x); - yy1 = (int )rint((g->geom.height-1-e->p.line.dim.y1) + g->geom.y-g->wp.y); - yy2 = (int )rint((g->geom.height-1-e->p.line.dim.y2) + g->geom.y-g->wp.y); + xx1 = (int )lrint(e->p.line.dim.x1 + g->geom.x - g->wp.x); + xx2 = (int )lrint(e->p.line.dim.x2 + g->geom.x - g->wp.x); + yy1 = (int )lrint((g->geom.height-1-e->p.line.dim.y1) + g->geom.y-g->wp.y); + yy2 = (int )lrint((g->geom.height-1-e->p.line.dim.y2) + g->geom.y-g->wp.y); /* If line completely out of the area, we won't show it */ if (((xx1 < 0) && (xx2 < 0)) || ((xx1 >= g->wp.width) && (xx2 >= g->wp.width)) || @@ -2183,7 +2187,7 @@ static void v_axis_pixmap_draw(struct axis *axis) for (i=imin; i <= imax; i++) { gint w, h; char desc[32]; - int y = (int) (g->geom.height - 1 - (int )rint(i * major_tick) - + int y = (int) (g->geom.height - 1 - (int )lrint(i * major_tick) - offset + corr + axis->s.y); debug(DBS_AXES_DRAWING) printf("%f @ %d\n", @@ -2207,7 +2211,7 @@ static void v_axis_pixmap_draw(struct axis *axis) imin = (int) ((g->geom.height - offset + corr - g->wp.height)/minor_tick + 1); imax = (int) ((g->geom.height - offset + corr) / minor_tick); for (i=imin; i <= imax; i++) { - int y = (int) (g->geom.height-1 - (int )rint (i*minor_tick) - + int y = (int) (g->geom.height-1 - (int )lrint(i*minor_tick) - offset + corr + axis->s.y); debug(DBS_AXES_DRAWING) printf("%f @ %d\n", i*axis->minor+fl, y); @@ -2549,18 +2553,18 @@ static int line_detect_collision(struct element *e, int x, int y) int xx1, yy1, xx2, yy2; if (e->p.line.dim.x1 < e->p.line.dim.x2) { - xx1 = (int )rint(e->p.line.dim.x1); - xx2 = (int )rint(e->p.line.dim.x2); + xx1 = (int )lrint(e->p.line.dim.x1); + xx2 = (int )lrint(e->p.line.dim.x2); } else { - xx1 = (int )rint(e->p.line.dim.x2); - xx2 = (int )rint(e->p.line.dim.x1); + xx1 = (int )lrint(e->p.line.dim.x2); + xx2 = (int )lrint(e->p.line.dim.x1); } if (e->p.line.dim.y1 < e->p.line.dim.y2) { - yy1 = (int )rint(e->p.line.dim.y1); - yy2 = (int )rint(e->p.line.dim.y2); + yy1 = (int )lrint(e->p.line.dim.y1); + yy2 = (int )lrint(e->p.line.dim.y2); } else { - yy1 = (int )rint(e->p.line.dim.y2); - yy2 = (int )rint(e->p.line.dim.y1); + yy1 = (int )lrint(e->p.line.dim.y2); + yy2 = (int )lrint(e->p.line.dim.y1); } /* printf("line: (%d,%d)->(%d,%d), clicked: (%d,%d)\n", xx1, yy1, xx2, yy2, x, y); @@ -2576,10 +2580,10 @@ static int ellipse_detect_collision(struct element *e, int x, int y) { int xx1, yy1, xx2, yy2; - xx1 = (int )rint(e->p.ellipse.dim.x); - xx2 = (int )rint(e->p.ellipse.dim.x + e->p.ellipse.dim.width); - yy1 = (int )rint(e->p.ellipse.dim.y - e->p.ellipse.dim.height); - yy2 = (int )rint(e->p.ellipse.dim.y); + xx1 = (int )lrint(e->p.ellipse.dim.x); + xx2 = (int )lrint(e->p.ellipse.dim.x + e->p.ellipse.dim.width); + yy1 = (int )lrint(e->p.ellipse.dim.y - e->p.ellipse.dim.height); + yy2 = (int )lrint(e->p.ellipse.dim.y); /* printf("ellipse: (%d,%d)->(%d,%d), clicked: (%d,%d)\n", xx1, yy1, xx2, yy2, x, y); */ @@ -2698,8 +2702,8 @@ static void magnify_create(struct gtk_graph *g, int x, int y) mg->wp.y = 0; mg->wp.width = g->magnify.width; mg->wp.height = g->magnify.height; - mg->geom.width = (int )rint(g->geom.width * g->magnify.zoom.x); - mg->geom.height = (int )rint(g->geom.height * g->magnify.zoom.y); + mg->geom.width = (int )lrint(g->geom.width * g->magnify.zoom.x); + mg->geom.height = (int )lrint(g->geom.height * g->magnify.zoom.y); mg->zoom.x = (mg->geom.width - 1) / g->bounds.width; mg->zoom.y = (mg->geom.height- 1) / g->bounds.height; @@ -2791,9 +2795,9 @@ static void magnify_get_geom(struct gtk_graph *g, int x, int y) g->magnify.g->geom.x = g->geom.x; g->magnify.g->geom.y = g->geom.y; - g->magnify.g->geom.x -= (int )rint((g->magnify.g->geom.width - g->geom.width) * + g->magnify.g->geom.x -= (int )lrint((g->magnify.g->geom.width - g->geom.width) * ((x-g->geom.x)/(double )g->geom.width)); - g->magnify.g->geom.y -= (int )rint((g->magnify.g->geom.height - g->geom.height) * + g->magnify.g->geom.y -= (int )lrint((g->magnify.g->geom.height - g->geom.height) * ((y-g->geom.y)/(double )g->geom.height)); /* we have coords of origin of graph relative to origin of g->toplevel. @@ -2861,8 +2865,8 @@ static gboolean configure_event(GtkWidget *widget _U_, GdkEventConfigure *event, zoom.y = (double )g->wp.height / cur_wp_height; cur_g_width = g->geom.width; cur_g_height = g->geom.height; - g->geom.width = (int )rint(g->geom.width * zoom.x); - g->geom.height = (int )rint(g->geom.height * zoom.y); + g->geom.width = (int )lrint(g->geom.width * zoom.x); + g->geom.height = (int )lrint(g->geom.height * zoom.y); g->zoom.x = (double )(g->geom.width - 1) / g->bounds.width; g->zoom.y = (double )(g->geom.height -1) / g->bounds.height; /* g->zoom.initial.x = g->zoom.x; */ @@ -2965,8 +2969,8 @@ perform_zoom(struct gtk_graph *g, struct zoomfactor *zf, int cur_width = g->geom.width, cur_height = g->geom.height; /* Multiply by x and y factors */ - g->geom.width = (int )rint(g->geom.width * zf->x); - g->geom.height = (int )rint(g->geom.height * zf->y); + g->geom.width = (int )lrint(g->geom.width * zf->x); + g->geom.height = (int )lrint(g->geom.height * zf->y); /* If already fully-zoomed out, don't waste time re-drawing */ if ((g->geom.width <= g->wp.width) && @@ -2986,9 +2990,9 @@ perform_zoom(struct gtk_graph *g, struct zoomfactor *zf, g->zoom.y = (g->geom.height- 1) / g->bounds.height; /* Move origin to keep mouse position at centre of view */ - g->geom.x -= (int)rint((g->geom.width - cur_width) * + g->geom.x -= (int)lrint((g->geom.width - cur_width) * ((origin_x - g->geom.x)/(double )cur_width)); - g->geom.y -= (int)rint((g->geom.height - cur_height) * + g->geom.y -= (int)lrint((g->geom.height - cur_height) * ((origin_y - g->geom.y)/(double )cur_height)); if (g->geom.x > g->wp.x) @@ -3213,7 +3217,7 @@ static void do_magnify_create(struct gtk_graph *g) int pointer_x, pointer_y; get_mouse_position(g->drawing_area, &pointer_x, &pointer_y, NULL); - magnify_create(g, (int )rint(pointer_x), (int )rint(pointer_y)); + magnify_create(g, (int )lrint(pointer_x), (int )lrint(pointer_y)); } static void do_key_motion(struct gtk_graph *g) @@ -3271,10 +3275,10 @@ static gboolean button_press_event(GtkWidget *widget _U_, GdkEventButton *event, if (event->button == MOUSE_BUTTON_RIGHT) { if (event->state & GDK_CONTROL_MASK) { - magnify_create(g, (int )rint(event->x), (int )rint(event->y)); + magnify_create(g, (int )lrint(event->x), (int )lrint(event->y)); } else { - g->grab.x = (int )rint(event->x) - g->geom.x; - g->grab.y = (int )rint(event->y) - g->geom.y; + g->grab.x = (int )lrint(event->x) - g->geom.x; + g->grab.y = (int )lrint(event->y) - g->geom.y; g->grab.grabbed = TRUE; } #ifdef ORIGINAL_WIN32_BUTTONS |