summaryrefslogtreecommitdiff
path: root/math/gnuplot+/files/patch-xe
blob: cc9cb87da2904905c79daa371371a43ece0e9186 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# contour.c.fix.991130
--- contour.c.ORIG	Thu Dec  3 22:23:46 1998
+++ contour.c	Wed Dec  1 21:07:24 1999
@@ -536,8 +536,8 @@
 struct edge_struct **p_edges; /* list of edges output */
 {
     int i, j, grid_x_max = iso_lines->p_count;
-    struct edge_struct *p_edge1, *p_edge2, *edge0, *edge1, *edge2, *pe_tail,
-    *pe_tail1, *pe_tail2, *pe_temp;
+    struct edge_struct *p_edge1, *p_edge2, *edge0, *edge1, *edge2,
+           *pe_tail, *pe_tail2, *pe_temp;
     struct poly_struct *pp_tail, *lower_tri, *upper_tri;
     struct coordinate GPHUGE *p_vrtx1, GPHUGE * p_vrtx2;	/* HBB 980308: need to tag *each* of them as GPHUGE! */
 
@@ -545,14 +545,14 @@
     (*p_edges) = pe_tail = NULL;
 
     p_vrtx1 = iso_lines->points;	/* first row of vertices */
-    p_edge1 = pe_tail1 = NULL;	/* clear list of edges */
+    p_edge1 = pe_tail = NULL;	/* clear list of edges */
 
     /* Generate edges of first row */
+    /* HBB 19991130: removed effectively unused variable 'pe_tail1' */
     for (j = 0; j < grid_x_max - 1; j++)
-	add_edge(p_vrtx1 + j, p_vrtx1 + j + 1, &p_edge1, &pe_tail1);
+	add_edge(p_vrtx1 + j, p_vrtx1 + j + 1, &p_edge1, &pe_tail);
 
     (*p_edges) = p_edge1;	/* update main list */
-    pe_tail = pe_tail1;
 
 
     /*
@@ -562,10 +562,16 @@
      * (pe_tail points on last edge).
      *
      * Temporary pointers:
-     * 1. p_edge2: Top horizontal edge list:       -----------------------  2
-     * 2. pe_tail: middle edge list:              |\  |\  |\  |\  |\  |\  |
+     * 1. p_edge2: Top horizontal edge list:      +-----------------------+ 2
+     * 2. p_tail : end of middle edge list:       |\  |\  |\  |\  |\  |\  |
      *                                            |  \|  \|  \|  \|  \|  \|
-     * 3. p_edge1: Bottom horizontal edge list:    -----------------------  1
+     * 3. p_edge1: Bottom horizontal edge list:   +-----------------------+ 1
+     *
+     * pe_tail2  : end of list beginning at p_edge2
+     * pe_temp   : position inside list beginning at p_edge1
+     * p_edges   : head of the master edge list (part of our output)
+     * p_vrtx1   : start of lower row of input vertices
+     * p_vrtx2   : start of higher row of input vertices
      *
      * The routine generates two triangle            Lower      Upper 1  
      * upper one and lower one:                     | \           ----   
@@ -633,14 +639,21 @@
 	    upper_tri = add_poly(edge0, edge1, edge2, p_polys, &pp_tail);
 	}
 
-	if ((*p_edges)) {	/* Chain new edges to main list. */
-	    pe_tail->next = p_edge2;
-	    pe_tail = pe_tail2;
-	} else {
-	    (*p_edges) = p_edge2;
-	    pe_tail = pe_tail2;
+        if (p_edge2) {
+	    /* HBB 19991130 bugfix: if p_edge2 list is empty,
+	     * don't change p_edges list! Crashes by access
+	     * to NULL pointer pe_tail, the second time through,
+	     * otherwise */
+	    if ((*p_edges)) {	/* Chain new edges to main list. */
+		pe_tail->next = p_edge2;
+		pe_tail = pe_tail2;
+	    } else {
+		(*p_edges) = p_edge2;
+		pe_tail = pe_tail2;
+	    }
 	}
 
+	/* this row finished, move list heads up one row: */
 	p_edge1 = p_edge2;
 	p_vrtx1 = p_vrtx2;
     }