From 04e6c2e6a8dbd04dfd81d6b1d43bb34767260cf0 Mon Sep 17 00:00:00 2001 From: roundup976 Date: Sun, 24 Sep 2023 20:30:36 -0400 Subject: [PATCH 01/15] ignore vim swap files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index bb34c7f72..8277c10f4 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ build-release/ *.pyc build-aux/flatpak/build/ .flatpak-builder +*.swp -- GitLab From 4159e314fe448c132e45497dcfc1c38f02155aac Mon Sep 17 00:00:00 2001 From: roundup976 Date: Tue, 26 Sep 2023 20:48:03 -0400 Subject: [PATCH 02/15] issue 507 add check for NULL pointer Check that the DDisplay object diagram->data->selected is not null before calling diagram_find_closest_handle in diagram.c. --- app/modify_tool.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/modify_tool.c b/app/modify_tool.c index aa3623ad0..6319cb759 100644 --- a/app/modify_tool.c +++ b/app/modify_tool.c @@ -483,7 +483,10 @@ modify_motion (ModifyTool *tool, DiaObject *obj = NULL; Handle *handle = NULL; - diagram_find_closest_handle (ddisp->diagram, &handle, &obj, &to); + if (ddisp->diagram->data->selected) { + diagram_find_closest_handle (ddisp->diagram, &handle, &obj, &to); + } + if (handle && handle->type != HANDLE_NON_MOVABLE && handle->id >= HANDLE_RESIZE_NW && handle->id <= HANDLE_RESIZE_SE && handle_is_clicked(ddisp, handle, &to) -- GitLab From f690944a30fc18e95301ec4563194f4eeb32317b Mon Sep 17 00:00:00 2001 From: roundup976 Date: Thu, 28 Sep 2023 19:38:21 -0400 Subject: [PATCH 03/15] change call to only perform check if selected not null Only 3 functions call diagram_find_closest_handle and two of them check that handle is not null before using the return. Changed the third caller to do this also rather than just fixing the function calling diagram_find_closest_handle that has the problem in issue 507. --- app/diagram.c | 31 +++++++++++++++++-------------- app/modify_tool.c | 5 ++++- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/app/diagram.c b/app/diagram.c index 00d1989fb..89648ab5a 100644 --- a/app/diagram.c +++ b/app/diagram.c @@ -1080,22 +1080,25 @@ diagram_find_closest_handle(Diagram *dia, Handle **closest, *closest = NULL; - l = dia->data->selected; - while (l!=NULL) { - obj = (DiaObject *) l->data; - - for (i=0;inum_handles;i++) { - handle = obj->handles[i]; - /* Note: Uses manhattan metric for speed... */ - dist = distance_point_point_manhattan(pos, &handle->pos); - if (dist<=mindist) { - mindist = dist; - *closest = handle; - *object = obj; + /* issue 507: check that selected is not null */ + if (dia->data->selected) { + l = dia->data->selected; + while (l!=NULL) { + obj = (DiaObject *) l->data; + + for (i=0;inum_handles;i++) { + handle = obj->handles[i]; + /* Note: Uses manhattan metric for speed... */ + dist = distance_point_point_manhattan(pos, &handle->pos); + if (dist<=mindist) { + mindist = dist; + *closest = handle; + *object = obj; + } } - } - l = g_list_next(l); + l = g_list_next(l); + } } return mindist; diff --git a/app/modify_tool.c b/app/modify_tool.c index 6319cb759..522f3007e 100644 --- a/app/modify_tool.c +++ b/app/modify_tool.c @@ -243,7 +243,7 @@ static int do_if_clicked_handle(DDisplay *ddisp, ModifyTool *tool, handle = NULL; diagram_find_closest_handle(ddisp->diagram, &handle, &obj, clickedpoint); - if (handle_is_clicked(ddisp, handle, clickedpoint)) { + if (handle && handle_is_clicked(ddisp, handle, clickedpoint)) { tool->state = STATE_MOVE_HANDLE; tool->break_connections = TRUE; tool->last_to = handle->pos; @@ -483,9 +483,12 @@ modify_motion (ModifyTool *tool, DiaObject *obj = NULL; Handle *handle = NULL; +#if 0 if (ddisp->diagram->data->selected) { diagram_find_closest_handle (ddisp->diagram, &handle, &obj, &to); } +#endif + diagram_find_closest_handle (ddisp->diagram, &handle, &obj, &to); if (handle && handle->type != HANDLE_NON_MOVABLE && handle->id >= HANDLE_RESIZE_NW && handle->id <= HANDLE_RESIZE_SE -- GitLab From 92e8a9106dc51ad299baabff4abd5e0e023a72d2 Mon Sep 17 00:00:00 2001 From: roundup976 Date: Thu, 28 Sep 2023 19:51:30 -0400 Subject: [PATCH 04/15] move 1000000.0 into a macro and update comments --- app/diagram.c | 17 +++++++++++++---- app/diagram.h | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/diagram.c b/app/diagram.c index 89648ab5a..b4aeb517a 100644 --- a/app/diagram.c +++ b/app/diagram.c @@ -1062,9 +1062,18 @@ diagram_find_clicked_object_except (Diagram *dia, avoid); } -/* - * Always returns the last handle in an object that has - * the closest distance +/*! + * \brief Always returns the last handle in an object that has + * the closest distance unless dia->data->selected was + * null. Check that Handle object is not null. + * + * \param dia Diagram object + * \param closest Handle object + * \param object DiaObject + * \param pos Point object + * + * \return last Handle with closest distance or DIA_REALLY_BIG_VALUE + * if dia->data->selected is null */ real diagram_find_closest_handle(Diagram *dia, Handle **closest, @@ -1076,7 +1085,7 @@ diagram_find_closest_handle(Diagram *dia, Handle **closest, real mindist, dist; int i; - mindist = 1000000.0; /* Realy big value... */ + mindist = DIA_REALLY_BIG_VALUE; /* Realy big value... */ *closest = NULL; diff --git a/app/diagram.h b/app/diagram.h index 1edc26fd2..5f1b17cad 100644 --- a/app/diagram.h +++ b/app/diagram.h @@ -37,6 +37,7 @@ GType dia_diagram_get_type (void) G_GNUC_CONST; #define DIA_DIAGRAM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DIA_TYPE_DIAGRAM, DiagramClass)) #define DIA_IS_DIAGRAM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_DIAGRAM)) #define DIA_DIAGRAM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DIA_TYPE_DIAGRAM, DiagramClass)) +#define DIA_REALLY_BIG_VALUE 1000000.0 struct _Diagram { DiagramData parent_instance; -- GitLab From dcfc2bda35f71b8553ffb25e7296f80671eba07d Mon Sep 17 00:00:00 2001 From: roundup976 Date: Fri, 29 Sep 2023 21:32:59 -0400 Subject: [PATCH 05/15] remove dead code and issue comment --- app/diagram.c | 1 - app/modify_tool.c | 5 ----- 2 files changed, 6 deletions(-) diff --git a/app/diagram.c b/app/diagram.c index b4aeb517a..9b9369feb 100644 --- a/app/diagram.c +++ b/app/diagram.c @@ -1089,7 +1089,6 @@ diagram_find_closest_handle(Diagram *dia, Handle **closest, *closest = NULL; - /* issue 507: check that selected is not null */ if (dia->data->selected) { l = dia->data->selected; while (l!=NULL) { diff --git a/app/modify_tool.c b/app/modify_tool.c index 522f3007e..0cdae46ce 100644 --- a/app/modify_tool.c +++ b/app/modify_tool.c @@ -483,11 +483,6 @@ modify_motion (ModifyTool *tool, DiaObject *obj = NULL; Handle *handle = NULL; -#if 0 - if (ddisp->diagram->data->selected) { - diagram_find_closest_handle (ddisp->diagram, &handle, &obj, &to); - } -#endif diagram_find_closest_handle (ddisp->diagram, &handle, &obj, &to); if (handle && handle->type != HANDLE_NON_MOVABLE -- GitLab From 2837555375f0cb2e744aed6ff880f32eb548506e Mon Sep 17 00:00:00 2001 From: roundup976 Date: Wed, 4 Oct 2023 17:01:49 -0400 Subject: [PATCH 06/15] removed vim swap file per merge request --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8277c10f4..bb34c7f72 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,3 @@ build-release/ *.pyc build-aux/flatpak/build/ .flatpak-builder -*.swp -- GitLab From 2b0d985330ff2a925aff93482728488c1856965a Mon Sep 17 00:00:00 2001 From: roundup976 Date: Wed, 4 Oct 2023 17:02:21 -0400 Subject: [PATCH 07/15] remove line between call and if statement per suggestion --- app/modify_tool.c | 1 - 1 file changed, 1 deletion(-) diff --git a/app/modify_tool.c b/app/modify_tool.c index 0cdae46ce..9c03d8473 100644 --- a/app/modify_tool.c +++ b/app/modify_tool.c @@ -484,7 +484,6 @@ modify_motion (ModifyTool *tool, Handle *handle = NULL; diagram_find_closest_handle (ddisp->diagram, &handle, &obj, &to); - if (handle && handle->type != HANDLE_NON_MOVABLE && handle->id >= HANDLE_RESIZE_NW && handle->id <= HANDLE_RESIZE_SE && handle_is_clicked(ddisp, handle, &to) -- GitLab From 283bf12c28aec2f0f8f21d6f9d5cfc2c516027aa Mon Sep 17 00:00:00 2001 From: roundup976 Date: Fri, 6 Oct 2023 15:13:57 -0400 Subject: [PATCH 08/15] some changes suggested by review --- app/diagram.c | 50 ++++++++++++++++++++++++----------------------- app/modify_tool.c | 2 +- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/app/diagram.c b/app/diagram.c index 9b9369feb..7ed8cee68 100644 --- a/app/diagram.c +++ b/app/diagram.c @@ -1062,18 +1062,18 @@ diagram_find_clicked_object_except (Diagram *dia, avoid); } -/*! - * \brief Always returns the last handle in an object that has +/** + * @brief Always returns the last handle in an object that has * the closest distance unless dia->data->selected was * null. Check that Handle object is not null. * - * \param dia Diagram object - * \param closest Handle object - * \param object DiaObject - * \param pos Point object + * @dia: Diagram object + * @closest: (out): Handle object + * @object: DiaObject + * @pos: Point object * - * \return last Handle with closest distance or DIA_REALLY_BIG_VALUE - * if dia->data->selected is null + * @return last Handle with closest distance or DIA_REALLY_BIG_VALUE + * if nothing is selected */ real diagram_find_closest_handle(Diagram *dia, Handle **closest, @@ -1089,24 +1089,26 @@ diagram_find_closest_handle(Diagram *dia, Handle **closest, *closest = NULL; - if (dia->data->selected) { - l = dia->data->selected; - while (l!=NULL) { - obj = (DiaObject *) l->data; - - for (i=0;inum_handles;i++) { - handle = obj->handles[i]; - /* Note: Uses manhattan metric for speed... */ - dist = distance_point_point_manhattan(pos, &handle->pos); - if (dist<=mindist) { - mindist = dist; - *closest = handle; - *object = obj; - } - } + if (!dia->data->selected) { + return mindist; + } - l = g_list_next(l); + l = dia->data->selected; + while (l!=NULL) { + obj = (DiaObject *) l->data; + + for (i=0;inum_handles;i++) { + handle = obj->handles[i]; + /* Note: Uses manhattan metric for speed... */ + dist = distance_point_point_manhattan(pos, &handle->pos); + if (dist<=mindist) { + mindist = dist; + *closest = handle; + *object = obj; + } } + + l = g_list_next(l); } return mindist; diff --git a/app/modify_tool.c b/app/modify_tool.c index 9c03d8473..df7621d2c 100644 --- a/app/modify_tool.c +++ b/app/modify_tool.c @@ -243,7 +243,7 @@ static int do_if_clicked_handle(DDisplay *ddisp, ModifyTool *tool, handle = NULL; diagram_find_closest_handle(ddisp->diagram, &handle, &obj, clickedpoint); - if (handle && handle_is_clicked(ddisp, handle, clickedpoint)) { + if (handle && handle_is_clicked(ddisp, handle, clickedpoint)) { tool->state = STATE_MOVE_HANDLE; tool->break_connections = TRUE; tool->last_to = handle->pos; -- GitLab From 2911f4e7e90f808c58e4f544ce23898410c46791 Mon Sep 17 00:00:00 2001 From: roundup976 Date: Fri, 6 Oct 2023 15:16:00 -0400 Subject: [PATCH 09/15] add G_UNLIKELY in for branch prediction/doc --- app/diagram.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/diagram.c b/app/diagram.c index 7ed8cee68..1ce2f4b2a 100644 --- a/app/diagram.c +++ b/app/diagram.c @@ -1089,7 +1089,7 @@ diagram_find_closest_handle(Diagram *dia, Handle **closest, *closest = NULL; - if (!dia->data->selected) { + if (G_UNLIKELY(!dia->data->selected)) { return mindist; } -- GitLab From ecff8efd00b6d124c4195392fbf2041068bfd6f5 Mon Sep 17 00:00:00 2001 From: roundup976 Date: Fri, 6 Oct 2023 16:51:22 -0400 Subject: [PATCH 10/15] remove define on large distance value --- app/diagram.h | 1 - 1 file changed, 1 deletion(-) diff --git a/app/diagram.h b/app/diagram.h index 5f1b17cad..1edc26fd2 100644 --- a/app/diagram.h +++ b/app/diagram.h @@ -37,7 +37,6 @@ GType dia_diagram_get_type (void) G_GNUC_CONST; #define DIA_DIAGRAM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DIA_TYPE_DIAGRAM, DiagramClass)) #define DIA_IS_DIAGRAM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_DIAGRAM)) #define DIA_DIAGRAM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DIA_TYPE_DIAGRAM, DiagramClass)) -#define DIA_REALLY_BIG_VALUE 1000000.0 struct _Diagram { DiagramData parent_instance; -- GitLab From ff0723b1c61e9d551b181c1410041b1dcb39eefa Mon Sep 17 00:00:00 2001 From: roundup976 Date: Fri, 6 Oct 2023 16:51:54 -0400 Subject: [PATCH 11/15] update func comment to gnome standard; revert define to 1 million --- app/diagram.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/diagram.c b/app/diagram.c index 1ce2f4b2a..e45a8811b 100644 --- a/app/diagram.c +++ b/app/diagram.c @@ -1063,16 +1063,17 @@ diagram_find_clicked_object_except (Diagram *dia, } /** - * @brief Always returns the last handle in an object that has - * the closest distance unless dia->data->selected was - * null. Check that Handle object is not null. - * + * diagram_find_closest_hanle: * @dia: Diagram object * @closest: (out): Handle object * @object: DiaObject * @pos: Point object * - * @return last Handle with closest distance or DIA_REALLY_BIG_VALUE + * Always returns the last handle in an object that has + * the closest distance unless dia->data->selected was + * null. Check that Handle object is not null. + * + * Return: last Handle with closest distance or DIA_REALLY_BIG_VALUE * if nothing is selected */ real @@ -1085,11 +1086,11 @@ diagram_find_closest_handle(Diagram *dia, Handle **closest, real mindist, dist; int i; - mindist = DIA_REALLY_BIG_VALUE; /* Realy big value... */ + mindist = 1000000.0; /* Realy big value... */ *closest = NULL; - if (G_UNLIKELY(!dia->data->selected)) { + if (G_UNLIKELY (!dia->data->selected)) { return mindist; } -- GitLab From c994288548894f7c77531b65138930e8ebc89712 Mon Sep 17 00:00:00 2001 From: roundup976 Date: Fri, 6 Oct 2023 16:52:50 -0400 Subject: [PATCH 12/15] add space after func name --- app/modify_tool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/modify_tool.c b/app/modify_tool.c index df7621d2c..1bbb21e06 100644 --- a/app/modify_tool.c +++ b/app/modify_tool.c @@ -243,7 +243,7 @@ static int do_if_clicked_handle(DDisplay *ddisp, ModifyTool *tool, handle = NULL; diagram_find_closest_handle(ddisp->diagram, &handle, &obj, clickedpoint); - if (handle && handle_is_clicked(ddisp, handle, clickedpoint)) { + if (handle && handle_is_clicked (ddisp, handle, clickedpoint)) { tool->state = STATE_MOVE_HANDLE; tool->break_connections = TRUE; tool->last_to = handle->pos; -- GitLab From b7f726fe0a8469e70260663ec422571e1820523c Mon Sep 17 00:00:00 2001 From: roundup976 Date: Fri, 6 Oct 2023 16:55:14 -0400 Subject: [PATCH 13/15] remove ref to define in block comment --- app/diagram.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/diagram.c b/app/diagram.c index e45a8811b..ffa0a10fa 100644 --- a/app/diagram.c +++ b/app/diagram.c @@ -1073,7 +1073,7 @@ diagram_find_clicked_object_except (Diagram *dia, * the closest distance unless dia->data->selected was * null. Check that Handle object is not null. * - * Return: last Handle with closest distance or DIA_REALLY_BIG_VALUE + * Return: last Handle with closest distance or 1000000.0 * if nothing is selected */ real -- GitLab From bb2667215df3dd8e9aa6d247fd941df6dfd39389 Mon Sep 17 00:00:00 2001 From: roundup976 Date: Fri, 6 Oct 2023 17:53:52 -0400 Subject: [PATCH 14/15] change Return to Returns --- app/diagram.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/diagram.c b/app/diagram.c index ffa0a10fa..b8f216189 100644 --- a/app/diagram.c +++ b/app/diagram.c @@ -1073,8 +1073,8 @@ diagram_find_clicked_object_except (Diagram *dia, * the closest distance unless dia->data->selected was * null. Check that Handle object is not null. * - * Return: last Handle with closest distance or 1000000.0 - * if nothing is selected + * Returns: last Handle with closest distance or 1000000.0 + * if nothing is selected */ real diagram_find_closest_handle(Diagram *dia, Handle **closest, -- GitLab From c13be3525a92ada5e49aeafe340d7103d35b9c1f Mon Sep 17 00:00:00 2001 From: roundup976 Date: Fri, 6 Oct 2023 17:56:45 -0400 Subject: [PATCH 15/15] correct spelling on handle --- app/diagram.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/diagram.c b/app/diagram.c index b8f216189..ada63e12c 100644 --- a/app/diagram.c +++ b/app/diagram.c @@ -1063,7 +1063,7 @@ diagram_find_clicked_object_except (Diagram *dia, } /** - * diagram_find_closest_hanle: + * diagram_find_closest_handle: * @dia: Diagram object * @closest: (out): Handle object * @object: DiaObject -- GitLab