Commit d464e315 authored by Thomas G. Lockhart's avatar Thomas G. Lockhart

Remove valid pointer checks for returns from palloc() since palloc() will not

return if storage is not allocated. Ref: Vadim 97/05/01
parent 36d18351
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.4 1997/04/25 18:40:25 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.5 1997/05/06 07:27:51 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -180,14 +180,11 @@ int path_decode(int opentype, int npts, char *str, int *isopen, char **ss, Point ...@@ -180,14 +180,11 @@ int path_decode(int opentype, int npts, char *str, int *isopen, char **ss, Point
char *path_encode( bool closed, int npts, Point *pt) char *path_encode( bool closed, int npts, Point *pt)
{ {
char *result; char *result = PALLOC(npts*(P_MAXLEN+3)+2);
char *cp; char *cp;
int i; int i;
if (!PointerIsValid(result = (char *)PALLOC(npts*(P_MAXLEN+3)+2)))
elog(WARN, "Memory allocation failed, can't output path", NULL);
cp = result; cp = result;
switch (closed) { switch (closed) {
case TRUE: case TRUE:
...@@ -261,7 +258,7 @@ int pair_count(char *s, char delim) ...@@ -261,7 +258,7 @@ int pair_count(char *s, char delim)
*/ */
BOX *box_in(char *str) BOX *box_in(char *str)
{ {
BOX *box; BOX *box = PALLOCTYPE(BOX);
int isopen; int isopen;
char *s; char *s;
...@@ -270,9 +267,6 @@ BOX *box_in(char *str) ...@@ -270,9 +267,6 @@ BOX *box_in(char *str)
if (!PointerIsValid((char *)str)) if (!PointerIsValid((char *)str))
elog (WARN," Bad (null) box external representation",NULL); elog (WARN," Bad (null) box external representation",NULL);
if (!PointerIsValid(box = PALLOCTYPE(BOX)))
elog(WARN, "Memory allocation failed, can't input box '%s'",str);
if ((! path_decode(FALSE, 2, str, &isopen, &s, &(box->high))) if ((! path_decode(FALSE, 2, str, &isopen, &s, &(box->high)))
|| (*s != '\0')) || (*s != '\0'))
elog (WARN, "Bad box external representation '%s'",str); elog (WARN, "Bad box external representation '%s'",str);
...@@ -297,7 +291,7 @@ BOX *box_in(char *str) ...@@ -297,7 +291,7 @@ BOX *box_in(char *str)
char *box_out(BOX *box) char *box_out(BOX *box)
{ {
#if OLD_FORMAT_OUT #if OLD_FORMAT_OUT
char *result; char *result = PALLOC(2*(P_MAXLEN+1)+2);
char *cp; char *cp;
#endif #endif
...@@ -306,9 +300,6 @@ char *box_out(BOX *box) ...@@ -306,9 +300,6 @@ char *box_out(BOX *box)
return(NULL); return(NULL);
#if OLD_FORMAT_OUT #if OLD_FORMAT_OUT
if (!PointerIsValid(result = (char *)PALLOC(2*(P_MAXLEN+1)+2)))
elog(WARN, "Memory allocation failed, can't output box", NULL);
cp = result; cp = result;
*cp++ = LDELIM; *cp++ = LDELIM;
if (! pair_encode( box->high.x, box->high.y, cp)) if (! pair_encode( box->high.x, box->high.y, cp))
...@@ -332,9 +323,8 @@ char *box_out(BOX *box) ...@@ -332,9 +323,8 @@ char *box_out(BOX *box)
*/ */
BOX *box_construct(double x1, double x2, double y1, double y2) BOX *box_construct(double x1, double x2, double y1, double y2)
{ {
BOX *result; BOX *result = PALLOCTYPE(BOX);
result = PALLOCTYPE(BOX);
return( box_fill(result, x1, x2, y1, y2) ); return( box_fill(result, x1, x2, y1, y2) );
} }
...@@ -366,9 +356,8 @@ BOX *box_fill(BOX *result, double x1, double x2, double y1, double y2) ...@@ -366,9 +356,8 @@ BOX *box_fill(BOX *result, double x1, double x2, double y1, double y2)
*/ */
BOX *box_copy(BOX *box) BOX *box_copy(BOX *box)
{ {
BOX *result; BOX *result = PALLOCTYPE(BOX);
result = PALLOCTYPE(BOX);
memmove((char *) result, (char *) box, sizeof(BOX)); memmove((char *) result, (char *) box, sizeof(BOX));
return(result); return(result);
...@@ -507,9 +496,8 @@ bool box_ge(BOX *box1, BOX *box2) ...@@ -507,9 +496,8 @@ bool box_ge(BOX *box1, BOX *box2)
*/ */
double *box_area(BOX *box) double *box_area(BOX *box)
{ {
double *result; double *result = PALLOCTYPE(double);
result = PALLOCTYPE(double);
*result = box_ln(box) * box_ht(box); *result = box_ln(box) * box_ht(box);
return(result); return(result);
...@@ -521,9 +509,8 @@ double *box_area(BOX *box) ...@@ -521,9 +509,8 @@ double *box_area(BOX *box)
*/ */
double *box_length(BOX *box) double *box_length(BOX *box)
{ {
double *result; double *result = PALLOCTYPE(double);
result = PALLOCTYPE(double);
*result = box->high.x - box->low.x; *result = box->high.x - box->low.x;
return(result); return(result);
...@@ -535,9 +522,8 @@ double *box_length(BOX *box) ...@@ -535,9 +522,8 @@ double *box_length(BOX *box)
*/ */
double *box_height(BOX *box) double *box_height(BOX *box)
{ {
double *result; double *result = PALLOCTYPE(double);
result = PALLOCTYPE(double);
*result = box->high.y - box->low.y; *result = box->high.y - box->low.y;
return(result); return(result);
...@@ -549,10 +535,9 @@ double *box_height(BOX *box) ...@@ -549,10 +535,9 @@ double *box_height(BOX *box)
*/ */
double *box_distance(BOX *box1, BOX *box2) double *box_distance(BOX *box1, BOX *box2)
{ {
double *result; double *result = PALLOCTYPE(double);
Point *a, *b; Point *a, *b;
result = PALLOCTYPE(double);
a = box_center(box1); a = box_center(box1);
b = box_center(box2); b = box_center(box2);
*result = HYPOT(a->x - b->x, a->y - b->y); *result = HYPOT(a->x - b->x, a->y - b->y);
...@@ -567,9 +552,8 @@ double *box_distance(BOX *box1, BOX *box2) ...@@ -567,9 +552,8 @@ double *box_distance(BOX *box1, BOX *box2)
*/ */
Point *box_center(BOX *box) Point *box_center(BOX *box)
{ {
Point *result; Point *result = PALLOCTYPE(Point);
result = PALLOCTYPE(Point);
result->x = (box->high.x + box->low.x) / 2.0; result->x = (box->high.x + box->low.x) / 2.0;
result->y = (box->high.y + box->low.y) / 2.0; result->y = (box->high.y + box->low.y) / 2.0;
...@@ -634,7 +618,9 @@ BOX *box_intersect(BOX *box1, BOX *box2) ...@@ -634,7 +618,9 @@ BOX *box_intersect(BOX *box1, BOX *box2)
if (! box_overlap(box1,box2)) if (! box_overlap(box1,box2))
return(NULL); return(NULL);
result = PALLOCTYPE(BOX); result = PALLOCTYPE(BOX);
result->high.x = Min(box1->high.x, box2->high.x); result->high.x = Min(box1->high.x, box2->high.x);
result->low.x = Max(box1->low.x, box2->low.x); result->low.x = Max(box1->low.x, box2->low.x);
result->high.y = Min(box1->high.y, box2->high.y); result->high.y = Min(box1->high.y, box2->high.y);
...@@ -678,9 +664,8 @@ LSEG *box_diagonal(BOX *box) ...@@ -678,9 +664,8 @@ LSEG *box_diagonal(BOX *box)
LINE * /* point-slope */ LINE * /* point-slope */
line_construct_pm(Point *pt, double m) line_construct_pm(Point *pt, double m)
{ {
LINE *result; LINE *result = PALLOCTYPE(LINE);
result = PALLOCTYPE(LINE);
/* use "mx - y + yinter = 0" */ /* use "mx - y + yinter = 0" */
result->A = m; result->A = m;
result->B = -1.0; result->B = -1.0;
...@@ -692,9 +677,8 @@ line_construct_pm(Point *pt, double m) ...@@ -692,9 +677,8 @@ line_construct_pm(Point *pt, double m)
LINE * /* two points */ LINE * /* two points */
line_construct_pp(Point *pt1, Point *pt2) line_construct_pp(Point *pt1, Point *pt2)
{ {
LINE *result; LINE *result = PALLOCTYPE(LINE);
result = PALLOCTYPE(LINE);
if (FPeq(pt1->x, pt2->x)) { /* vertical */ if (FPeq(pt1->x, pt2->x)) { /* vertical */
/* use "x = C" */ /* use "x = C" */
result->m = 0.0; result->m = 0.0;
...@@ -771,10 +755,9 @@ bool line_eq(LINE *l1, LINE *l2) ...@@ -771,10 +755,9 @@ bool line_eq(LINE *l1, LINE *l2)
double * /* distance between l1, l2 */ double * /* distance between l1, l2 */
line_distance(LINE *l1, LINE *l2) line_distance(LINE *l1, LINE *l2)
{ {
double *result; double *result = PALLOCTYPE(double);
Point *tmp; Point *tmp;
result = PALLOCTYPE(double);
if (line_intersect(l1, l2)) { if (line_intersect(l1, l2)) {
*result = 0.0; *result = 0.0;
return(result); return(result);
...@@ -867,8 +850,7 @@ PATH *path_in(char *str) ...@@ -867,8 +850,7 @@ PATH *path_in(char *str)
#endif #endif
size = offsetof(PATH, p[0]) + (sizeof(path->p[0]) * npts); size = offsetof(PATH, p[0]) + (sizeof(path->p[0]) * npts);
if (!PointerIsValid(path = PALLOC(size))) path = PALLOC(size);
elog(WARN, "Memory allocation failed, can't input path '%s'",str);
path->size = size; path->size = size;
path->npts = npts; path->npts = npts;
...@@ -908,8 +890,7 @@ char *path_out(PATH *path) ...@@ -908,8 +890,7 @@ char *path_out(PATH *path)
return NULL; return NULL;
#if OLD_FORMAT_OUT #if OLD_FORMAT_OUT
if (!PointerIsValid(result = (char *)PALLOC(path->npts*(P_MAXLEN+3)+2))) result = PALLOC(path->npts*(P_MAXLEN+3)+2);
elog(WARN, "Memory allocation failed, can't output path", NULL);
cp = result; cp = result;
*cp++ = LDELIM; *cp++ = LDELIM;
...@@ -1033,8 +1014,7 @@ path_copy(PATH *path) ...@@ -1033,8 +1014,7 @@ path_copy(PATH *path)
return NULL; return NULL;
size = offsetof(PATH, p[0]) + (sizeof(path->p[0]) * path->npts); size = offsetof(PATH, p[0]) + (sizeof(path->p[0]) * path->npts);
if (!PointerIsValid(result = PALLOC(size))) result = PALLOC(size);
elog(WARN, "Memory allocation failed, can't copy path",NULL);
memmove((char *) result, (char *) path, size); memmove((char *) result, (char *) path, size);
return(result); return(result);
...@@ -1124,10 +1104,9 @@ double *path_distance(PATH *p1, PATH *p2) ...@@ -1124,10 +1104,9 @@ double *path_distance(PATH *p1, PATH *p2)
double *path_length(PATH *path) double *path_length(PATH *path)
{ {
double *result; double *result = PALLOCTYPE(double);
int ct, i; int ct, i;
result = PALLOCTYPE(double);
ct = path->npts - 1; ct = path->npts - 1;
for (i = 0; i < ct; i++) for (i = 0; i < ct; i++)
*result += point_dt(&path->p[i], &path->p[i+1]); *result += point_dt(&path->p[i], &path->p[i+1]);
...@@ -1177,8 +1156,7 @@ point_in(char *str) ...@@ -1177,8 +1156,7 @@ point_in(char *str)
if (! pair_decode( str, &x, &y, &s) || (strlen(s) > 0)) if (! pair_decode( str, &x, &y, &s) || (strlen(s) > 0))
elog (WARN, "Bad point external representation '%s'",str); elog (WARN, "Bad point external representation '%s'",str);
if (!PointerIsValid(point = PALLOCTYPE(Point))) point = PALLOCTYPE(Point);
elog (WARN, "Unable to allocate point storage for '%s'",str);
point->x = x; point->x = x;
point->y = y; point->y = y;
...@@ -1198,9 +1176,8 @@ point_out(Point *pt) ...@@ -1198,9 +1176,8 @@ point_out(Point *pt)
Point *point_construct(double x, double y) Point *point_construct(double x, double y)
{ {
Point *result; Point *result = PALLOCTYPE(Point);
result = PALLOCTYPE(Point);
result->x = x; result->x = x;
result->y = y; result->y = y;
return(result); return(result);
...@@ -1209,9 +1186,8 @@ Point *point_construct(double x, double y) ...@@ -1209,9 +1186,8 @@ Point *point_construct(double x, double y)
Point *point_copy(Point *pt) Point *point_copy(Point *pt)
{ {
Point *result; Point *result = PALLOCTYPE(Point);
result = PALLOCTYPE(Point);
result->x = pt->x; result->x = pt->x;
result->y = pt->y; result->y = pt->y;
return(result); return(result);
...@@ -1276,9 +1252,8 @@ int32 pointdist(Point *p1, Point *p2) ...@@ -1276,9 +1252,8 @@ int32 pointdist(Point *p1, Point *p2)
double *point_distance(Point *pt1, Point *pt2) double *point_distance(Point *pt1, Point *pt2)
{ {
double *result; double *result = PALLOCTYPE(double);
result = PALLOCTYPE(double);
*result = HYPOT( pt1->x - pt2->x, pt1->y - pt2->y ); *result = HYPOT( pt1->x - pt2->x, pt1->y - pt2->y );
return(result); return(result);
} }
...@@ -1291,9 +1266,8 @@ double point_dt(Point *pt1, Point *pt2) ...@@ -1291,9 +1266,8 @@ double point_dt(Point *pt1, Point *pt2)
double *point_slope(Point *pt1, Point *pt2) double *point_slope(Point *pt1, Point *pt2)
{ {
double *result; double *result = PALLOCTYPE(double);
result = PALLOCTYPE(double);
if (point_vert(pt1, pt2)) if (point_vert(pt1, pt2))
*result = (double)DBL_MAX; *result = (double)DBL_MAX;
else else
...@@ -1335,8 +1309,7 @@ LSEG *lseg_in(char *str) ...@@ -1335,8 +1309,7 @@ LSEG *lseg_in(char *str)
if (!PointerIsValid((char *)str)) if (!PointerIsValid((char *)str))
elog (WARN," Bad (null) lseg external representation",NULL); elog (WARN," Bad (null) lseg external representation",NULL);
if (!PointerIsValid(lseg = PALLOCTYPE(LSEG))) lseg = PALLOCTYPE(LSEG);
elog(WARN, "Memory allocation failed, can't input lseg '%s'",str);
if ((! path_decode(TRUE, 2, str, &isopen, &s, &(lseg->p[0]))) if ((! path_decode(TRUE, 2, str, &isopen, &s, &(lseg->p[0])))
|| (*s != '\0')) || (*s != '\0'))
...@@ -1362,9 +1335,8 @@ char *lseg_out(LSEG *ls) ...@@ -1362,9 +1335,8 @@ char *lseg_out(LSEG *ls)
*/ */
LSEG *lseg_construct(Point *pt1, Point *pt2) LSEG *lseg_construct(Point *pt1, Point *pt2)
{ {
LSEG *result; LSEG *result = PALLOCTYPE(LSEG);
result = PALLOCTYPE(LSEG);
result->p[0].x = pt1->x; result->p[0].x = pt1->x;
result->p[0].y = pt1->y; result->p[0].y = pt1->y;
result->p[1].x = pt2->x; result->p[1].x = pt2->x;
...@@ -1456,9 +1428,8 @@ bool lseg_eq(LSEG *l1, LSEG *l2) ...@@ -1456,9 +1428,8 @@ bool lseg_eq(LSEG *l1, LSEG *l2)
*/ */
double *lseg_distance(LSEG *l1, LSEG *l2) double *lseg_distance(LSEG *l1, LSEG *l2)
{ {
double *result; double *result = PALLOCTYPE(double);
result = PALLOCTYPE(double);
*result = lseg_dt( l1, l2); *result = lseg_dt( l1, l2);
return(result); return(result);
...@@ -1533,9 +1504,8 @@ Point *lseg_interpt(LSEG *l1, LSEG *l2) ...@@ -1533,9 +1504,8 @@ Point *lseg_interpt(LSEG *l1, LSEG *l2)
double *dist_pl(Point *pt, LINE *line) double *dist_pl(Point *pt, LINE *line)
{ {
double *result; double *result = PALLOCTYPE(double);
result = PALLOCTYPE(double);
*result = (line->A * pt->x + line->B * pt->y + line->C) / *result = (line->A * pt->x + line->B * pt->y + line->C) /
HYPOT(line->A, line->B); HYPOT(line->A, line->B);
...@@ -2040,8 +2010,7 @@ POLYGON *poly_in(char *str) ...@@ -2040,8 +2010,7 @@ POLYGON *poly_in(char *str)
elog(WARN, "Bad polygon external representation '%s'", str); elog(WARN, "Bad polygon external representation '%s'", str);
size = offsetof(POLYGON, p[0]) + (sizeof(poly->p[0]) * npts); size = offsetof(POLYGON, p[0]) + (sizeof(poly->p[0]) * npts);
if (!PointerIsValid(poly = (POLYGON *) PALLOC(size))) poly = PALLOC(size);
elog(WARN, "Memory allocation failed, can't input polygon '%s'",str);
memset((char *) poly, 0, size); /* zero any holes */ memset((char *) poly, 0, size); /* zero any holes */
poly->size = size; poly->size = size;
...@@ -2124,8 +2093,7 @@ char *poly_out(POLYGON *poly) ...@@ -2124,8 +2093,7 @@ char *poly_out(POLYGON *poly)
return NULL; return NULL;
#if OLD_FORMAT_OUT #if OLD_FORMAT_OUT
if (!PointerIsValid(result = (char *)PALLOC(poly->npts*(P_MAXLEN+3)+2))) result = PALLOC(poly->npts*(P_MAXLEN+3)+2);
elog(WARN, "Memory allocation failed, can't output polygon", NULL);
cp = result; cp = result;
*cp++ = LDELIM; *cp++ = LDELIM;
...@@ -2255,8 +2223,7 @@ point_add(Point *p1, Point *p2) ...@@ -2255,8 +2223,7 @@ point_add(Point *p1, Point *p2)
if (! (PointerIsValid(p1) && PointerIsValid(p2))) if (! (PointerIsValid(p1) && PointerIsValid(p2)))
return(NULL); return(NULL);
if (!PointerIsValid(result = PALLOCTYPE(Point))) result = PALLOCTYPE(Point);
elog(WARN, "Memory allocation failed, can't add points",NULL);
result->x = (p1->x + p2->x); result->x = (p1->x + p2->x);
result->y = (p1->y + p2->y); result->y = (p1->y + p2->y);
...@@ -2272,8 +2239,7 @@ point_sub(Point *p1, Point *p2) ...@@ -2272,8 +2239,7 @@ point_sub(Point *p1, Point *p2)
if (! (PointerIsValid(p1) && PointerIsValid(p2))) if (! (PointerIsValid(p1) && PointerIsValid(p2)))
return(NULL); return(NULL);
if (!PointerIsValid(result = PALLOCTYPE(Point))) result = PALLOCTYPE(Point);
elog(WARN, "Memory allocation failed, can't add points",NULL);
result->x = (p1->x - p2->x); result->x = (p1->x - p2->x);
result->y = (p1->y - p2->y); result->y = (p1->y - p2->y);
...@@ -2289,8 +2255,7 @@ point_mul(Point *p1, Point *p2) ...@@ -2289,8 +2255,7 @@ point_mul(Point *p1, Point *p2)
if (! (PointerIsValid(p1) && PointerIsValid(p2))) if (! (PointerIsValid(p1) && PointerIsValid(p2)))
return(NULL); return(NULL);
if (!PointerIsValid(result = PALLOCTYPE(Point))) result = PALLOCTYPE(Point);
elog(WARN, "Memory allocation failed, can't multiply points",NULL);
result->x = (p1->x*p2->x) - (p1->y*p2->y); result->x = (p1->x*p2->x) - (p1->y*p2->y);
result->y = (p1->x*p2->y) + (p1->y*p2->x); result->y = (p1->x*p2->y) + (p1->y*p2->x);
...@@ -2307,8 +2272,7 @@ point_div(Point *p1, Point *p2) ...@@ -2307,8 +2272,7 @@ point_div(Point *p1, Point *p2)
if (! (PointerIsValid(p1) && PointerIsValid(p2))) if (! (PointerIsValid(p1) && PointerIsValid(p2)))
return(NULL); return(NULL);
if (!PointerIsValid(result = PALLOCTYPE(Point))) result = PALLOCTYPE(Point);
elog(WARN, "Memory allocation failed, can't multiply path",NULL);
div = (p2->x*p2->x) + (p2->y*p2->y); div = (p2->x*p2->x) + (p2->y*p2->y);
...@@ -2438,8 +2402,7 @@ path_add(PATH *p1, PATH *p2) ...@@ -2438,8 +2402,7 @@ path_add(PATH *p1, PATH *p2)
return(NULL); return(NULL);
size = offsetof(PATH, p[0]) + (sizeof(p1->p[0]) * (p1->npts+p2->npts)); size = offsetof(PATH, p[0]) + (sizeof(p1->p[0]) * (p1->npts+p2->npts));
if (!PointerIsValid(result = PALLOC(size))) result = PALLOC(size);
elog(WARN, "Memory allocation failed, can't add paths",NULL);
result->size = size; result->size = size;
result->npts = (p1->npts+p2->npts); result->npts = (p1->npts+p2->npts);
...@@ -2564,8 +2527,7 @@ POLYGON *path_poly(PATH *path) ...@@ -2564,8 +2527,7 @@ POLYGON *path_poly(PATH *path)
elog(WARN, "Open path cannot be converted to polygon",NULL); elog(WARN, "Open path cannot be converted to polygon",NULL);
size = offsetof(POLYGON, p[0]) + (sizeof(poly->p[0]) * path->npts); size = offsetof(POLYGON, p[0]) + (sizeof(poly->p[0]) * path->npts);
if (!PointerIsValid(poly = PALLOC(size))) poly = PALLOC(size);
elog(WARN, "Memory allocation failed, can't convert path to polygon",NULL);
poly->size = size; poly->size = size;
poly->npts = path->npts; poly->npts = path->npts;
...@@ -2609,6 +2571,9 @@ poly_box(POLYGON *poly) ...@@ -2609,6 +2571,9 @@ poly_box(POLYGON *poly)
return(box); return(box);
} /* poly_box() */ } /* poly_box() */
/* box_poly()
* Convert a box to a polygon.
*/
POLYGON * POLYGON *
box_poly(BOX *box) box_poly(BOX *box)
{ {
...@@ -2618,9 +2583,9 @@ box_poly(BOX *box) ...@@ -2618,9 +2583,9 @@ box_poly(BOX *box)
if (!PointerIsValid(box)) if (!PointerIsValid(box))
return(NULL); return(NULL);
/* map four corners of the box to a polygon */
size = offsetof(POLYGON, p[0]) + (sizeof(poly->p[0]) * 4); size = offsetof(POLYGON, p[0]) + (sizeof(poly->p[0]) * 4);
if (!PointerIsValid(poly = PALLOC(size))) poly = PALLOC(size);
elog(WARN, "Memory allocation failed, can't convert box to polygon",NULL);
poly->size = size; poly->size = size;
poly->npts = 4; poly->npts = 4;
...@@ -2650,8 +2615,7 @@ poly_path(POLYGON *poly) ...@@ -2650,8 +2615,7 @@ poly_path(POLYGON *poly)
return(NULL); return(NULL);
size = offsetof(PATH, p[0]) + (sizeof(path->p[0]) * poly->npts); size = offsetof(PATH, p[0]) + (sizeof(path->p[0]) * poly->npts);
if (!PointerIsValid(path = PALLOC(size))) path = PALLOC(size);
elog(WARN, "Memory allocation failed, can't convert polygon to path",NULL);
path->size = size; path->size = size;
path->npts = poly->npts; path->npts = poly->npts;
...@@ -2675,7 +2639,7 @@ poly_path(POLYGON *poly) ...@@ -2675,7 +2639,7 @@ poly_path(POLYGON *poly)
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.4 1997/04/25 18:40:25 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.5 1997/05/06 07:27:51 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -2739,8 +2703,7 @@ CIRCLE *circle_in(char *str) ...@@ -2739,8 +2703,7 @@ CIRCLE *circle_in(char *str)
if (!PointerIsValid(str)) if (!PointerIsValid(str))
elog (WARN," Bad (null) circle external representation",NULL); elog (WARN," Bad (null) circle external representation",NULL);
if (!PointerIsValid(circle = PALLOCTYPE(CIRCLE))) circle = PALLOCTYPE(CIRCLE);
elog(WARN, "Memory allocation failed, can't input circle '%s'",str);
s = str; s = str;
while (isspace( *s)) s++; while (isspace( *s)) s++;
...@@ -2789,8 +2752,7 @@ char *circle_out(CIRCLE *circle) ...@@ -2789,8 +2752,7 @@ char *circle_out(CIRCLE *circle)
if (!PointerIsValid(circle)) if (!PointerIsValid(circle))
return(NULL); return(NULL);
if (!PointerIsValid(result = (char *)PALLOC(3*(P_MAXLEN+1)+3))) result = PALLOC(3*(P_MAXLEN+1)+3);
elog(WARN, "Memory allocation failed, can't output circle", NULL);
cp = result; cp = result;
*cp++ = LDELIM_C; *cp++ = LDELIM_C;
...@@ -2944,8 +2906,7 @@ circle_copy(CIRCLE *circle) ...@@ -2944,8 +2906,7 @@ circle_copy(CIRCLE *circle)
if (!PointerIsValid(circle)) if (!PointerIsValid(circle))
return NULL; return NULL;
if (!PointerIsValid(result = PALLOCTYPE(CIRCLE))) result = PALLOCTYPE(CIRCLE);
elog(WARN, "Memory allocation failed, can't copy circle",NULL);
memmove((char *) result, (char *) circle, sizeof(CIRCLE)); memmove((char *) result, (char *) circle, sizeof(CIRCLE));
return(result); return(result);
...@@ -3152,8 +3113,7 @@ CIRCLE *circle(Point *center, float8 *radius) ...@@ -3152,8 +3113,7 @@ CIRCLE *circle(Point *center, float8 *radius)
if (! (PointerIsValid(center) && PointerIsValid(radius))) if (! (PointerIsValid(center) && PointerIsValid(radius)))
return(NULL); return(NULL);
if (!PointerIsValid(result = PALLOCTYPE(CIRCLE))) result = PALLOCTYPE(CIRCLE);
elog(WARN, "Memory allocation failed, can't convert point to circle",NULL);
result->center.x = center->x; result->center.x = center->x;
result->center.y = center->y; result->center.y = center->y;
...@@ -3176,8 +3136,7 @@ POLYGON *circle_poly(int npts, CIRCLE *circle) ...@@ -3176,8 +3136,7 @@ POLYGON *circle_poly(int npts, CIRCLE *circle)
elog (WARN, "Unable to convert circle to polygon", NULL); elog (WARN, "Unable to convert circle to polygon", NULL);
size = offsetof(POLYGON, p[0]) + (sizeof(poly->p[0]) * npts); size = offsetof(POLYGON, p[0]) + (sizeof(poly->p[0]) * npts);
if (!PointerIsValid(poly = (POLYGON *) PALLOC(size))) poly = PALLOC(size);
elog(WARN, "Memory allocation failed, can't convert circle to polygon",NULL);
memset((char *) poly, 0, size); /* zero any holes */ memset((char *) poly, 0, size); /* zero any holes */
poly->size = size; poly->size = size;
...@@ -3210,8 +3169,7 @@ CIRCLE *poly_circle(POLYGON *poly) ...@@ -3210,8 +3169,7 @@ CIRCLE *poly_circle(POLYGON *poly)
if (poly->npts <= 2) if (poly->npts <= 2)
elog (WARN, "Unable to convert polygon to circle", NULL); elog (WARN, "Unable to convert polygon to circle", NULL);
if (!PointerIsValid(circle = PALLOCTYPE(CIRCLE))) circle = PALLOCTYPE(CIRCLE);
elog(WARN, "Memory allocation failed, can't convert polygon to circle",NULL);
circle->center.x = 0; circle->center.x = 0;
circle->center.y = 0; circle->center.y = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment