From 166f9b6b18770f1bcdf32592642721a66ddcc8f4 Mon Sep 17 00:00:00 2001 From: Kaushik Raja Date: Mon, 20 Jul 2026 17:09:59 -0700 Subject: [PATCH] lib/proj: make METERS_in and METERS_out local to fix a data race The file-scope variables METERS_in and METERS_out were written on every call to GPJ_transform, GPJ_transform_array, pj_do_proj, and pj_do_transform. When GPJ_transform is called from multiple threads, ThreadSanitizer reports data races on both variables even when each thread uses its own cloned PJ object. Each function writes both variables before reading them, so they carry no state between calls. This change makes them locals of the four functions and removes the file-scope declaration. Output is unchanged. --- lib/proj/do_proj.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/proj/do_proj.c b/lib/proj/do_proj.c index 425431a6789..22c635310cc 100644 --- a/lib/proj/do_proj.c +++ b/lib/proj/do_proj.c @@ -39,8 +39,6 @@ } \ } while (0) -static double METERS_in = 1.0, METERS_out = 1.0; - int get_pj_area(const struct pj_info *iproj, double *xmin, double *xmax, double *ymin, double *ymax) { @@ -878,6 +876,7 @@ int GPJ_transform(const struct pj_info *info_in, const struct pj_info *info_out, int in_is_ll, out_is_ll, in_deg2rad, out_rad2deg; PJ_COORD c; + double METERS_in = 1.0, METERS_out = 1.0; if (info_in->pj == NULL) G_fatal_error(_("No input projection")); @@ -1040,6 +1039,7 @@ int GPJ_transform_array(const struct pj_info *info_in, /* PROJ 5+ variant */ int in_is_ll, out_is_ll, in_deg2rad, out_rad2deg; PJ_COORD c; + double METERS_in = 1.0, METERS_out = 1.0; if (info_trans->pj == NULL) G_fatal_error(_("No transformation object")); @@ -1236,6 +1236,7 @@ int pj_do_proj(double *x, double *y, const struct pj_info *info_in, struct pj_info info_trans; PJ_COORD c; + double METERS_in = 1.0, METERS_out = 1.0; if (GPJ_init_transform(info_in, info_out, &info_trans) < 0) { return -1; @@ -1325,6 +1326,7 @@ int pj_do_transform(int count, double *x, double *y, double *h, struct pj_info info_trans; PJ_COORD c; + double METERS_in = 1.0, METERS_out = 1.0; if (GPJ_init_transform(info_in, info_out, &info_trans) < 0) { return -1;