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/fwd.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'src/fwd.cpp') diff --git a/src/fwd.cpp b/src/fwd.cpp index 8583a6e7..c267dfca 100644 --- a/src/fwd.cpp +++ b/src/fwd.cpp @@ -193,9 +193,15 @@ PJ_XY pj_fwd(PJ_LP lp, PJ *P) { /* Do the transformation, using the lowest dimensional transformer available */ if (P->fwd) - coo.xy = P->fwd(coo.lp, P); + { + const auto xy = P->fwd(coo.lp, P); + coo.xy = xy; + } else if (P->fwd3d) - coo.xyz = P->fwd3d (coo.lpz, P); + { + const auto xyz = P->fwd3d (coo.lpz, P); + coo.xyz = xyz; + } else if (P->fwd4d) coo = P->fwd4d (coo, P); else { @@ -227,11 +233,17 @@ PJ_XYZ pj_fwd3d(PJ_LPZ lpz, PJ *P) { /* Do the transformation, using the lowest dimensional transformer feasible */ if (P->fwd3d) - coo.xyz = P->fwd3d(coo.lpz, P); + { + const auto xyz = P->fwd3d(coo.lpz, P); + coo.xyz = xyz; + } else if (P->fwd4d) coo = P->fwd4d (coo, P); else if (P->fwd) - coo.xy = P->fwd (coo.lp, P); + { + const auto xy = P->fwd (coo.lp, P); + coo.xy = xy; + } else { proj_errno_set (P, PROJ_ERR_OTHER_NO_INVERSE_OP); return proj_coord_error ().xyz; @@ -261,9 +273,15 @@ PJ_COORD pj_fwd4d (PJ_COORD coo, PJ *P) { if (P->fwd4d) coo = P->fwd4d (coo, P); else if (P->fwd3d) - coo.xyz = P->fwd3d (coo.lpz, P); + { + const auto xyz = P->fwd3d (coo.lpz, P); + coo.xyz = xyz; + } else if (P->fwd) - coo.xy = P->fwd (coo.lp, P); + { + const auto xy = P->fwd (coo.lp, P); + coo.xy = xy; + } else { proj_errno_set (P, PROJ_ERR_OTHER_NO_INVERSE_OP); return proj_coord_error (); -- cgit v1.2.3