File: 10_large-userscale.patch

package info (click to toggle)
xfig 1%3A3.2.8b-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 27,428 kB
  • sloc: ansic: 75,823; sh: 3,174; makefile: 303; javascript: 22; csh: 5
file content (152 lines) | stat: -rw-r--r-- 5,056 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
From: Thomas Loimer <thomas.loimer@tuwien.ac.at>
Date: Wed, 20 Jul 2022 07:37:45 +0200
Origin: upstream, https://sourceforge.net/p/mcj/xfig/ci/655cdf2
Bug: https://sourceforge.net/p/mcj/tickets/144/
Subject: Avoid SIGFPE with large -userscale, ticket #144
 Fix an issue whereupon, depending on metric or imperial mode and also the grid
 setting, setting the userscale to a large number might trigger SIGFPE. For
 instance, xfig -userscale 100 crashed.

--- a/src/w_canvas.c
+++ b/src/w_canvas.c
@@ -3,7 +3,7 @@
  * Copyright (c) 1985-1988 by Supoj Sutanthavibul
  * Parts Copyright (c) 1989-2007 by Brian V. Smith
  * Parts Copyright (c) 1991 by Paul King
- * Parts Copyright (c) 2016-2020 by Thomas Loimer
+ * Parts Copyright (c) 2016-2022 by Thomas Loimer
  *
  * Any party obtaining a copy of these files is granted, free of charge, a
  * full and unrestricted irrevocable, world-wide, paid up, royalty-free,
@@ -1102,7 +1102,7 @@ round_coords(int *x, int *y)
 	const int	half = spacing / 2;
 
 	/* make sure the cursor is on grid */
-	if (cur_pointposn == P_ANY || anypointposn)
+	if (cur_pointposn == P_ANY || anypointposn || spacing < 2)
 		return;
 
 	if (cur_gridtype == GRID_ISO) {
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -4,7 +4,7 @@
 # Copyright (c) 1985-1988 by Supoj Sutanthavibul
 # Parts Copyright (c) 1989-2015 by Brian V. Smith
 # Parts Copyright (c) 1991 by Paul King
-# Parts Copyright (c) 2016-2020 by Thomas Loimer
+# Parts Copyright (c) 2016-2022 by Thomas Loimer
 #
 # Any party obtaining a copy of these files is granted, free of charge, a
 # full and unrestricted irrevocable, world-wide, paid up, royalty-free,
@@ -17,7 +17,7 @@
 #
 #
 # tests/Makefile.am
-# Author: Thomas Loimer, 2016
+# Author: Thomas Loimer, 2016-2022
 
 # testsuite and package.m4 must be distributed, hence they are
 # written into the source tree
@@ -45,7 +45,7 @@ if ALLOW_MULTIPLE_DEFINITION
 AM_LDFLAGS = -Wl,--allow-multiple-definition $(XLDFLAGS)
 LDADD = $(top_builddir)/src/libxfig.a $(XLIBS)
 
-check_PROGRAMS = test1 test2 test3
+check_PROGRAMS = test1 test2 test3 test4
 
 $(top_builddir)/src/libxfig.a:
 	cd $(top_builddir)/src && $(MAKE) $(AM_MAKEFLAGS) libxfig.a
--- /dev/null
+++ b/tests/test4.c
@@ -0,0 +1,61 @@
+/*
+ * FIG : Facility for Interactive Generation of figures
+ * Copyright (c) 1985-1988 by Supoj Sutanthavibul
+ * Parts Copyright (c) 1989-2015 by Brian V. Smith
+ * Parts Copyright (c) 1991 by Paul King
+ * Parts Copyright (c) 2016-2022 by Thomas Loimer
+ *
+ * Any party obtaining a copy of these files is granted, free of charge, a
+ * full and unrestricted irrevocable, world-wide, paid up, royalty-free,
+ * nonexclusive right and license to deal in this software and documentation
+ * files (the "Software"), including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense and/or sell copies
+ * of the Software, and to permit persons who receive copies from any such
+ * party to do so, with the only requirement being that the above copyright
+ * and this permission notice remain intact.
+ *
+ */
+
+/*
+ *	test4.c: Test whether point_spacing() returning 0 causes an exception,
+ *		ticket #144.
+ *	Author: Thomas Loimer, 2022-07-20
+ *
+ * Make appres.userscale (xfig -userscale 100) large enough such that
+ * point_spacing() returns 0 and round_coords() calls round_square(), which
+ * eventually tries  x % spacing  , causing SIGFPE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <limits.h>
+#include <math.h>
+
+#include "fig.h"
+#include "resources.h"	/* must come before mode.h; struct appres */
+#include "mode.h"
+
+extern void round_coords(int *x, int *y);		/* w_canvas.h */
+
+/*
+ * defined in mode.h:
+ *	cur_gridunit		MM_UNIT, FRACT_UNIT, TENTH_UNIT
+ *	cur_pointposn		P_ANY, P_MAGNET, P_GRID1, ..., P_GRID4
+ *	anypointposn		True or False
+ */
+
+
+int
+main(void)
+{
+	int	x = 1;
+	int	y = 1;
+	appres.userscale = 100.0f;
+	anypointposn = 0;
+	cur_pointposn = P_GRID1;
+	round_coords(&x, &y);
+	return 0;
+}
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -2,7 +2,7 @@ AT_COPYRIGHT([FIG : Facility for Interac
 Copyright (c) 1985-1988 by Supoj Sutanthavibul
 Parts Copyright (c) 1989-2015 by Brian V. Smith
 Parts Copyright (c) 1991 by Paul King
-Parts Copyright (c) 2016-2020 by Thomas Loimer
+Parts Copyright (c) 2016-2022 by Thomas Loimer
 
 Any party obtaining a copy of these files is granted, free of charge, a
 full and unrestricted irrevocable, world-wide, paid up, royalty-free,
@@ -15,7 +15,7 @@ and this permission notice remain intact
 ])
 
 # testsuite.at
-# Author: Thomas Loimer, 2016
+# Author: Thomas Loimer, 2016-2022
 
 AT_INIT
 AT_COLOR_TESTS
@@ -98,3 +98,9 @@ AT_KEYWORDS([u_ghostscript.c])
 AT_SKIP_IF([test ! -x "$abs_builddir/test3"])
 AT_CHECK("$abs_builddir/test3" "$srcdir/data/cross.pdf", 0)
 AT_CLEANUP
+
+AT_SETUP([Test point_spacing() returning 0])
+AT_KEYWORDS(w_canvas.c)
+AT_SKIP_IF([test ! -x "$abs_builddir/test4"])
+AT_CHECK("$abs_builddir"/test4, 0)
+AT_CLEANUP