File tree 5 files changed +69
-14
lines changed
5 files changed +69
-14
lines changed Original file line number Diff line number Diff line change 1
1
#include <postgres.h>
2
2
#include <fmgr.h>
3
3
4
- #include <utils/geo_decls.h> /* Point */
5
-
6
- #include <point.h> /* SPoint */
7
4
#include <gnomo.h>
5
+ #include <point.h> /* SPoint from pgsphere */
8
6
9
7
#include <math.h>
10
8
Original file line number Diff line number Diff line change @@ -506,22 +506,26 @@ spherepath_in(PG_FUNCTION_ARGS)
506
506
char * c = PG_GETARG_CSTRING (0 );
507
507
int32 i , nelem ;
508
508
void sphere_yyparse (void );
509
- SPoint * arr ;
510
509
511
510
init_buffer (c );
512
511
sphere_yyparse ();
513
512
514
513
nelem = get_path_count ();
515
- if (nelem > 1 )
514
+ if (nelem > MAX_POINTS )
516
515
{
517
- arr = (SPoint * )palloc (sizeof (SPoint )* nelem );
516
+ reset_buffer ();
517
+ elog (ERROR , "spherepath_in: too much points" );
518
+ PG_RETURN_NULL ();
519
+ }
520
+ else if (nelem > 1 )
521
+ {
522
+ SPoint arr [MAX_POINTS ];
518
523
519
524
for (i = 0 ; i < nelem ; i ++ )
520
525
{
521
526
get_path_elem (i , & arr [i ].lng , & arr [i ].lat );
522
527
}
523
528
path = spherepath_from_array (& arr [0 ], nelem );
524
- pfree (arr );
525
529
}
526
530
else
527
531
{
Original file line number Diff line number Diff line change 35
35
36
36
#include "postgres.h"
37
37
#include "fmgr.h"
38
- #include "utils/geo_decls.h"
39
38
#include "utils/array.h"
40
39
#include "utils/elog.h"
41
40
#include "utils/builtins.h"
46
45
47
46
#include "pgs_util.h"
48
47
48
+ #define EPSILON 1.0E-09
49
+
50
+ #define FPzero (A ) (fabs(A) <= EPSILON)
51
+
52
+ static inline bool
53
+ FPeq (double A , double B )
54
+ {
55
+ return A == B || fabs (A - B ) <= EPSILON ;
56
+ }
57
+
58
+ static inline bool
59
+ FPne (double A , double B )
60
+ {
61
+ return A != B && fabs (A - B ) > EPSILON ;
62
+ }
63
+
64
+ static inline bool
65
+ FPlt (double A , double B )
66
+ {
67
+ return A + EPSILON < B ;
68
+ }
69
+
70
+ static inline bool
71
+ FPle (double A , double B )
72
+ {
73
+ return A <= B + EPSILON ;
74
+ }
75
+
76
+ static inline bool
77
+ FPgt (double A , double B )
78
+ {
79
+ return A > B + EPSILON ;
80
+ }
81
+
82
+ static inline bool
83
+ FPge (double A , double B )
84
+ {
85
+ return A + EPSILON >= B ;
86
+ }
87
+
88
+ /*---------------------------------------------------------------------
89
+ * Point - (x,y)
90
+ *-------------------------------------------------------------------*/
91
+ typedef struct
92
+ {
93
+ float8 x ,
94
+ y ;
95
+ } Point ;
96
+
49
97
void sphere_yyparse (void );
50
98
51
99
#endif
100
+
Original file line number Diff line number Diff line change @@ -815,24 +815,29 @@ spherepoly_in(PG_FUNCTION_ARGS)
815
815
char * c = PG_GETARG_CSTRING (0 );
816
816
int32 i ,
817
817
nelem ;
818
- SPoint * arr ;
819
818
820
819
void sphere_yyparse (void );
821
820
822
821
init_buffer (c );
823
822
sphere_yyparse ();
824
823
825
824
nelem = get_path_count ();
825
+ if (nelem > MAX_POINTS )
826
+ {
827
+ reset_buffer ();
828
+ elog (ERROR , "spherepoly_in: too much points" );
829
+ PG_RETURN_NULL ();
830
+
831
+ }
826
832
if (nelem > 2 )
827
833
{
828
- arr = ( SPoint * ) palloc ( sizeof ( SPoint ) * nelem ) ;
834
+ SPoint arr [ MAX_POINTS ] ;
829
835
830
836
for (i = 0 ; i < nelem ; i ++ )
831
837
{
832
838
get_path_elem (i , & arr [i ].lng , & arr [i ].lat );
833
839
}
834
840
poly = spherepoly_from_array (& arr [0 ], nelem );
835
- pfree (arr );
836
841
}
837
842
else
838
843
{
@@ -894,12 +899,11 @@ spherepoly_area(PG_FUNCTION_ARGS)
894
899
{
895
900
SPOLY * poly = PG_GETARG_SPOLY (0 );
896
901
int32 i ;
897
- SPoint * s ;
902
+ SPoint s [ MAX_POINTS + 2 ] ;
898
903
SPoint stmp [2 ];
899
904
SEuler se ;
900
905
float8 sum = 0.0 ;
901
906
902
- s = (SPoint * )palloc (sizeof (SPoint )* (poly -> npts + 2 ));
903
907
memcpy ((void * ) & s [1 ],
904
908
(void * ) & poly -> p [0 ],
905
909
poly -> npts * sizeof (SPoint ));
@@ -939,7 +943,6 @@ spherepoly_area(PG_FUNCTION_ARGS)
939
943
sum = 0.0 ;
940
944
}
941
945
942
- pfree (s );
943
946
PG_RETURN_FLOAT8 (sum );
944
947
}
945
948
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ typedef struct
17
17
SPoint p [1 ]; /* variable length array of SPoints */
18
18
} SPOLY ;
19
19
20
+ #define MAX_POINTS 1024
20
21
21
22
/* Polygon and ellipse */
22
23
#define PGS_ELLIPSE_POLY_AVOID 0 /* ellipse avoids polygon */
You can’t perform that action at this time.
0 commit comments