=================================================================== RCS file: /home/cvs/OpenXM_contrib/gnuplot/Attic/contour.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.3 diff -u -p -r1.1.1.1 -r1.1.1.3 --- OpenXM_contrib/gnuplot/Attic/contour.c 2000/01/09 17:00:50 1.1.1.1 +++ OpenXM_contrib/gnuplot/Attic/contour.c 2003/09/15 07:09:24 1.1.1.3 @@ -1,5 +1,5 @@ #ifndef lint -static char *RCSid = "$Id: contour.c,v 1.1.1.1 2000/01/09 17:00:50 maekawa Exp $"; +static char *RCSid = "$Id: contour.c,v 1.1.1.3 2003/09/15 07:09:24 ohara Exp $"; #endif /* GNUPLOT - contour.c */ @@ -289,10 +289,10 @@ static void end_crnt_cntr() { int i; struct gnuplot_contours *cntr = (struct gnuplot_contours *) - gp_alloc((unsigned long) sizeof(struct gnuplot_contours), "gnuplot_contour"); + gp_alloc(sizeof(struct gnuplot_contours), "gnuplot_contour"); cntr->coords = (struct coordinate GPHUGE *) - gp_alloc((unsigned long) sizeof(struct coordinate) - * (unsigned long) crnt_cntr_pt_index, "contour coords"); + gp_alloc(sizeof(struct coordinate) * crnt_cntr_pt_index, + "contour coords"); for (i = 0; i < crnt_cntr_pt_index; i++) { cntr->coords[i].x = crnt_cntr[i * 2]; @@ -501,7 +501,7 @@ double z_level; t = (t > 1.0 ? 1.0 : t); p_cntr = (struct cntr_struct *) - gp_alloc((unsigned long) sizeof(struct cntr_struct), "contour cntr_struct"); + gp_alloc(sizeof(struct cntr_struct), "contour cntr_struct"); p_cntr->X = p_edge->vertex[1]->x * t + p_edge->vertex[0]->x * (1 - t); @@ -536,8 +536,8 @@ struct poly_struct **p_polys; /* list of polygons outp 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 @@ struct edge_struct **p_edges; /* list of edges output (*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,11 +562,17 @@ struct edge_struct **p_edges; /* list of edges output * (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: | \ ---- * (Nums. are edges order in polys) 0| \1 0\ |2 @@ -633,14 +639,21 @@ struct edge_struct **p_edges; /* list of edges output 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; } @@ -714,10 +727,14 @@ struct edge_struct **p_edge, **pe_tail; /* pointers t { struct edge_struct *pe_temp = NULL; +#if 1 + if (point0->type == INRANGE && point1->type == INRANGE) { +#else if (point0->type != UNDEFINED && point1->type != UNDEFINED) { +#endif pe_temp = (struct edge_struct *) - gp_alloc((unsigned long) sizeof(struct edge_struct), "contour edge"); + gp_alloc(sizeof(struct edge_struct), "contour edge"); pe_temp->poly[0] = NULL; /* clear links */ pe_temp->poly[1] = NULL; @@ -752,7 +769,7 @@ struct poly_struct **p_poly, **pp_tail; /* pointers to if (edge0 && edge1 && edge2) { pp_temp = (struct poly_struct *) - gp_alloc((unsigned long) sizeof(struct poly_struct), "contour polygon"); + gp_alloc(sizeof(struct poly_struct), "contour polygon"); pp_temp->edge[0] = edge0; /* First edge of triangle */ pp_temp->edge[1] = edge1; /* Second one */ @@ -893,11 +910,11 @@ int contr_kind; } } delta_t = (double *) - gp_alloc((unsigned long) (sizeof(double) * num_pts), "contour delta_t"); + gp_alloc((sizeof(double) * num_pts), "contour delta_t"); d2x = (double *) - gp_alloc((unsigned long) (sizeof(double) * num_pts), "contour d2x"); + gp_alloc((sizeof(double) * num_pts), "contour d2x"); d2y = (double *) - gp_alloc((unsigned long) (sizeof(double) * num_pts), "contour d2y"); + gp_alloc((sizeof(double) * num_pts), "contour d2y"); /* Width and hight of the grid is used at unit length (2d-norm) */ unit_x = xx_max - x_min; @@ -1025,7 +1042,7 @@ double unit_x, unit_y; /* Unit length in x and y (norm struct cntr_struct *pc_temp; m = (tri_diag *) - gp_alloc((unsigned long) (sizeof(tri_diag) * num_pts), "contour tridiag m"); + gp_alloc((sizeof(tri_diag) * num_pts), "contour tridiag m"); /* * Calculate first differences in (d2x[i], d2y[i]) and interval lengths @@ -1385,9 +1402,9 @@ double *x, *y; double ti, tikp, *dx, *dy; /* Copy p_cntr into it to make it faster. */ dx = (double *) - gp_alloc((unsigned long) (sizeof(double) * (order + j)), "contour b_spline"); + gp_alloc((sizeof(double) * (order + j)), "contour b_spline"); dy = (double *) - gp_alloc((unsigned long) (sizeof(double) * (order + j)), "contour b_spline"); + gp_alloc((sizeof(double) * (order + j)), "contour b_spline"); /* Set the dx/dy - [0] iteration step, control points (p==0 iterat.): */ for (i = j - order; i <= j; i++) {