aboutsummaryrefslogtreecommitdiff
path: root/devel/libgpc/files/patch-alloca
blob: 6b45ec7a48db570edd75da5d17b2df4d4dc5a728 (plain) (blame)
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
Use alloca() instead of malloc()/free(), where it is easy to do.

Use BSD's err() instead of fprintf()/exit() on fatal failures.

When so exiting, use non-zero code to signal a failure.

	-mi

--- gpc.c	Fri Dec 17 10:39:26 2004
+++ gpc.c	Sat Oct 22 04:04:31 2005
@@ -39,4 +39,5 @@ Copyright: (C) 1997-2004, Advanced Inter
 
 #include "gpc.h"
+#include <err.h>
 #include <stdlib.h>
 #include <float.h>
@@ -104,6 +105,6 @@ Copyright: (C) 1997-2004, Advanced Inter
 #define MALLOC(p, b, s, t) {if ((b) > 0) { \
                             p= (t*)malloc(b); if (!(p)) { \
-                            fprintf(stderr, "gpc malloc failure: %s\n", s); \
-                            exit(0);}} else p= NULL;}
+                            err(1, "gpc: %s needed %zd bytes\n", s, \
+                            (size_t)b); }} else p= NULL;}
 
 #define FREE(p)            {if (p) {free(p); (p)= NULL;}}
@@ -965,6 +966,5 @@ static void minimax_test(gpc_polygon *su
   c_bbox= create_contour_bboxes(clip);
 
-  MALLOC(o_table, subj->num_contours * clip->num_contours * sizeof(int),
-         "overlap table creation", int);
+  o_table = alloca(subj->num_contours * clip->num_contours * sizeof(int));
 
   /* Check all subject contour bounding boxes against clip boxes */
@@ -1006,5 +1006,4 @@ static void minimax_test(gpc_polygon *su
   FREE(s_bbox);
   FREE(c_bbox);
-  FREE(o_table);
 }
 
@@ -1166,5 +1165,5 @@ void gpc_polygon_clip(gpc_op op, gpc_pol
 
   /* Build scanbeam table from scanbeam tree */
-  MALLOC(sbt, sbt_entries * sizeof(double), "sbt creation", double);
+  sbt = alloca(sbt_entries * sizeof(double));
   build_sbt(&scanbeam, sbt, sbtree);
   scanbeam= 0;
@@ -1749,5 +1748,4 @@ void gpc_polygon_clip(gpc_op op, gpc_pol
   FREE(c_heap);
   FREE(s_heap);
-  FREE(sbt);
 }
 
@@ -1825,5 +1823,5 @@ void gpc_tristrip_clip(gpc_op op, gpc_po
 
   /* Build scanbeam table from scanbeam tree */
-  MALLOC(sbt, sbt_entries * sizeof(double), "sbt creation", double);
+  sbt = alloca(sbt_entries * sizeof(double));
   build_sbt(&scanbeam, sbt, sbtree);
   scanbeam= 0;
@@ -2463,5 +2461,4 @@ void gpc_tristrip_clip(gpc_op op, gpc_po
   FREE(c_heap);
   FREE(s_heap);
-  FREE(sbt);
 }