# HG changeset patch # User jbe # Date 1761208745 -7200 # Node ID b9cdc74a90db87f143ba926e769e4bf766889cb3 # Parent 16787a19a325d8c04f3ef7bca25b20ad918aaf49 Clear memory of datums on allocation to avoid non-zero garbage in padding on all possible platforms diff -r 16787a19a325 -r b9cdc74a90db latlon-v0010.c --- a/latlon-v0010.c Thu Oct 23 10:16:01 2025 +0200 +++ b/latlon-v0010.c Thu Oct 23 10:39:05 2025 +0200 @@ -215,7 +215,7 @@ /* determine total number of points */ for (i=0; ibounding.center, cluster->bounding.radius + distance, /* pad bounding circle by distance */ @@ -1658,7 +1658,7 @@ /* create point ("epoint" in SQL) from latitude and longitude */ PG_FUNCTION_INFO_V1(pgl_create_epoint); Datum pgl_create_epoint(PG_FUNCTION_ARGS) { - pgl_point *point = (pgl_point *)palloc(sizeof(pgl_point)); + pgl_point *point = (pgl_point *)palloc0(sizeof(pgl_point)); pgl_epoint_set_latlon(point, PG_GETARG_FLOAT8(0), PG_GETARG_FLOAT8(1)); PG_RETURN_POINTER(point); } @@ -1685,7 +1685,7 @@ )); } /* allocate memory for result */ - point = (pgl_point *)palloc(sizeof(pgl_point)); + point = (pgl_point *)palloc0(sizeof(pgl_point)); /* set latitude and longitude (and perform checks) */ pgl_epoint_set_latlon(point, lat, lon); /* return result */ @@ -1718,7 +1718,7 @@ ("epoint_with_sample_count" in SQL) from epoint and integer */ PG_FUNCTION_INFO_V1(pgl_create_epoint_with_sample_count); Datum pgl_create_epoint_with_sample_count(PG_FUNCTION_ARGS) { - pgl_point_sc *search = (pgl_point_sc *)palloc(sizeof(pgl_point_sc)); + pgl_point_sc *search = (pgl_point_sc *)palloc0(sizeof(pgl_point_sc)); search->point = *(pgl_point *)PG_GETARG_POINTER(0); pgl_epoint_set_sample_count(search, PG_GETARG_INT32(1)); PG_RETURN_POINTER(search); @@ -1754,7 +1754,7 @@ )); } /* allocate memory for result */ - search = (pgl_point_sc *)palloc(sizeof(pgl_point_sc)); + search = (pgl_point_sc *)palloc0(sizeof(pgl_point_sc)); /* set latitude, longitude, and sample count (while performing checks) */ pgl_epoint_set_latlon(&search->point, lat, lon); pgl_epoint_set_sample_count(search, samples); @@ -1765,7 +1765,7 @@ /* create box ("ebox" in SQL) that is empty */ PG_FUNCTION_INFO_V1(pgl_create_empty_ebox); Datum pgl_create_empty_ebox(PG_FUNCTION_ARGS) { - pgl_box *box = (pgl_box *)palloc(sizeof(pgl_box)); + pgl_box *box = (pgl_box *)palloc0(sizeof(pgl_box)); pgl_box_set_empty(box); PG_RETURN_POINTER(box); } @@ -1832,7 +1832,7 @@ /* create box ("ebox" in SQL) from min/max latitude and min/max longitude */ PG_FUNCTION_INFO_V1(pgl_create_ebox); Datum pgl_create_ebox(PG_FUNCTION_ARGS) { - pgl_box *box = (pgl_box *)palloc(sizeof(pgl_box)); + pgl_box *box = (pgl_box *)palloc0(sizeof(pgl_box)); pgl_ebox_set_boundaries( box, PG_GETARG_FLOAT8(0), PG_GETARG_FLOAT8(1), @@ -1847,7 +1847,7 @@ Datum pgl_create_ebox_from_epoints(PG_FUNCTION_ARGS) { pgl_point *point1 = (pgl_point *)PG_GETARG_POINTER(0); pgl_point *point2 = (pgl_point *)PG_GETARG_POINTER(1); - pgl_box *box = (pgl_box *)palloc(sizeof(pgl_box)); + pgl_box *box = (pgl_box *)palloc0(sizeof(pgl_box)); double lat_min, lat_max, lon_min, lon_max; double dlon; /* longitude range (delta longitude) */ /* order latitude and longitude boundaries */ @@ -1911,7 +1911,7 @@ sscanf(strptr, " empty %n", &valid); if (valid && strptr[valid] == 0) { /* allocate and return empty box */ - box = (pgl_box *)palloc(sizeof(pgl_box)); + box = (pgl_box *)palloc0(sizeof(pgl_box)); pgl_box_set_empty(box); PG_RETURN_POINTER(box); } @@ -1946,7 +1946,7 @@ if (lat_min > lat_max) { val = lat_min; lat_min = lat_max; lat_max = val; } if (lon_min > lon_max) { val = lon_min; lon_min = lon_max; lon_max = val; } /* allocate memory for result */ - box = (pgl_box *)palloc(sizeof(pgl_box)); + box = (pgl_box *)palloc0(sizeof(pgl_box)); /* set boundaries (and perform checks) */ pgl_ebox_set_boundaries(box, lat_min, lat_max, lon_min, lon_max); /* return result */ @@ -1980,7 +1980,7 @@ /* create circle ("ecircle" in SQL) from latitude, longitude, and radius */ PG_FUNCTION_INFO_V1(pgl_create_ecircle); Datum pgl_create_ecircle(PG_FUNCTION_ARGS) { - pgl_circle *circle = (pgl_circle *)palloc(sizeof(pgl_circle)); + pgl_circle *circle = (pgl_circle *)palloc0(sizeof(pgl_circle)); pgl_ecircle_set_latlon_radius( circle, PG_GETARG_FLOAT8(0), PG_GETARG_FLOAT8(1), PG_GETARG_FLOAT8(2) ); @@ -1992,7 +1992,7 @@ Datum pgl_create_ecircle_from_epoint(PG_FUNCTION_ARGS) { pgl_point *point = (pgl_point *)PG_GETARG_POINTER(0); double radius = PG_GETARG_FLOAT8(1); - pgl_circle *circle = (pgl_circle *)palloc(sizeof(pgl_circle)); + pgl_circle *circle = (pgl_circle *)palloc0(sizeof(pgl_circle)); /* set latitude, longitude, radius (and perform checks) */ pgl_ecircle_set_latlon_radius(circle, point->lat, point->lon, radius); /* return result */ @@ -2028,7 +2028,7 @@ )); } /* allocate memory for result */ - circle = (pgl_circle *)palloc(sizeof(pgl_circle)); + circle = (pgl_circle *)palloc0(sizeof(pgl_circle)); /* set latitude, longitude, radius (and perform checks) */ pgl_ecircle_set_latlon_radius(circle, lat, lon, radius); /* return result */ @@ -2062,7 +2062,7 @@ /* reset reading position to start of (lowercase) string */ strptr = str_lower; /* allocate initial buffer for entries */ - entries = palloc(entries_buflen * sizeof(pgl_newentry)); + entries = palloc0(entries_buflen * sizeof(pgl_newentry)); /* parse until end of string */ while (strptr[0]) { /* require previous white-space or closing parenthesis before next token */ @@ -2107,7 +2107,7 @@ if (nentries == entries_buflen) { pgl_newentry *newbuf; entries_buflen *= 2; - newbuf = palloc(entries_buflen * sizeof(pgl_newentry)); + newbuf = palloc0(entries_buflen * sizeof(pgl_newentry)); memcpy(newbuf, entries, nentries * sizeof(pgl_newentry)); pfree(entries); entries = newbuf; @@ -2116,7 +2116,7 @@ npoints = 0; /* allocate array for points */ points_buflen = 4; - points = palloc(points_buflen * sizeof(pgl_point)); + points = palloc0(points_buflen * sizeof(pgl_point)); /* parse until closing parenthesis */ while (strptr[0] != ')') { /* error on unexpected end of string */ @@ -2147,7 +2147,7 @@ if (npoints == points_buflen) { pgl_point *newbuf; points_buflen *= 2; - newbuf = palloc(points_buflen * sizeof(pgl_point)); + newbuf = palloc0(points_buflen * sizeof(pgl_point)); memcpy(newbuf, points, npoints * sizeof(pgl_point)); pfree(points); points = newbuf; @@ -2358,7 +2358,7 @@ PG_FUNCTION_INFO_V1(pgl_epoint_recv); Datum pgl_epoint_recv(PG_FUNCTION_ARGS) { StringInfo buf = (StringInfo)PG_GETARG_POINTER(0); - pgl_point *point = (pgl_point *)palloc(sizeof(pgl_point)); + pgl_point *point = (pgl_point *)palloc0(sizeof(pgl_point)); point->lat = pq_getmsgfloat8(buf); point->lon = pq_getmsgfloat8(buf); PG_RETURN_POINTER(point); @@ -2368,7 +2368,7 @@ PG_FUNCTION_INFO_V1(pgl_ebox_recv); Datum pgl_ebox_recv(PG_FUNCTION_ARGS) { StringInfo buf = (StringInfo)PG_GETARG_POINTER(0); - pgl_box *box = (pgl_box *)palloc(sizeof(pgl_box)); + pgl_box *box = (pgl_box *)palloc0(sizeof(pgl_box)); box->lat_min = pq_getmsgfloat8(buf); box->lat_max = pq_getmsgfloat8(buf); box->lon_min = pq_getmsgfloat8(buf); @@ -2380,7 +2380,7 @@ PG_FUNCTION_INFO_V1(pgl_ecircle_recv); Datum pgl_ecircle_recv(PG_FUNCTION_ARGS) { StringInfo buf = (StringInfo)PG_GETARG_POINTER(0); - pgl_circle *circle = (pgl_circle *)palloc(sizeof(pgl_circle)); + pgl_circle *circle = (pgl_circle *)palloc0(sizeof(pgl_circle)); circle->center.lat = pq_getmsgfloat8(buf); circle->center.lon = pq_getmsgfloat8(buf); circle->radius = pq_getmsgfloat8(buf); @@ -2431,7 +2431,7 @@ PG_FUNCTION_INFO_V1(pgl_epoint_to_ebox); Datum pgl_epoint_to_ebox(PG_FUNCTION_ARGS) { pgl_point *point = (pgl_point *)PG_GETARG_POINTER(0); - pgl_box *box = palloc(sizeof(pgl_box)); + pgl_box *box = palloc0(sizeof(pgl_box)); box->lat_min = point->lat; box->lat_max = point->lat; box->lon_min = point->lon; @@ -2443,7 +2443,7 @@ PG_FUNCTION_INFO_V1(pgl_epoint_to_ecircle); Datum pgl_epoint_to_ecircle(PG_FUNCTION_ARGS) { pgl_point *point = (pgl_point *)PG_GETARG_POINTER(0); - pgl_circle *circle = palloc(sizeof(pgl_box)); + pgl_circle *circle = palloc0(sizeof(pgl_box)); circle->center = *point; circle->radius = 0; PG_RETURN_POINTER(circle);