From a767ae5d14063f3df1a3af994f26915f973de408 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 4 Sep 2021 18:00:20 +0200 Subject: Workaround 'Overlapping read/write of union is undefined behavior' cppcheck warning (but really fixing them would be more involved) --- src/inv.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'src/inv.cpp') diff --git a/src/inv.cpp b/src/inv.cpp index 8925f0e9..92b3c1d6 100644 --- a/src/inv.cpp +++ b/src/inv.cpp @@ -151,9 +151,15 @@ PJ_LP pj_inv(PJ_XY xy, PJ *P) { /* Do the transformation, using the lowest dimensional transformer available */ if (P->inv) - coo.lp = P->inv(coo.xy, P); + { + const auto lp = P->inv(coo.xy, P); + coo.lp = lp; + } else if (P->inv3d) - coo.lpz = P->inv3d (coo.xyz, P); + { + const auto lpz = P->inv3d (coo.xyz, P); + coo.lpz = lpz; + } else if (P->inv4d) coo = P->inv4d (coo, P); else { @@ -185,11 +191,17 @@ PJ_LPZ pj_inv3d (PJ_XYZ xyz, PJ *P) { /* Do the transformation, using the lowest dimensional transformer feasible */ if (P->inv3d) - coo.lpz = P->inv3d (coo.xyz, P); + { + const auto lpz = P->inv3d (coo.xyz, P); + coo.lpz = lpz; + } else if (P->inv4d) coo = P->inv4d (coo, P); else if (P->inv) - coo.lp = P->inv (coo.xy, P); + { + const auto lp = P->inv (coo.xy, P); + coo.lp = lp; + } else { proj_errno_set (P, PROJ_ERR_OTHER_NO_INVERSE_OP); return proj_coord_error ().lpz; @@ -219,9 +231,15 @@ PJ_COORD pj_inv4d (PJ_COORD coo, PJ *P) { if (P->inv4d) coo = P->inv4d (coo, P); else if (P->inv3d) - coo.lpz = P->inv3d (coo.xyz, P); + { + const auto lpz = P->inv3d (coo.xyz, P); + coo.lpz = lpz; + } else if (P->inv) - coo.lp = P->inv (coo.xy, P); + { + const auto lp = P->inv (coo.xy, P); + coo.lp = lp; + } else { proj_errno_set (P, PROJ_ERR_OTHER_NO_INVERSE_OP); return proj_coord_error (); -- cgit v1.2.3