-
Notifications
You must be signed in to change notification settings - Fork 752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable cppcheck and fix related mostly false-positive warnings #496
Conversation
fd35f0c
to
3db75dd
Compare
@@ -85,7 +85,10 @@ static void Init() { | |||
tolb = tol0 * tol2; | |||
xthresh = 1000 * tol2; | |||
degree = pi/180; | |||
NaN = sqrt(-1.0); | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this should be changed upstream?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cffk See above. One of the versions of cppcheck complains that sqrt(-1.0) is undefined, but later no longer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'll backport these changes. Also I note that Visual Studio gives two warnings
that S12 "may" be uninitialized. It's wrong! but I initialize it to 0 in those places together
with a comment /* Initialize S12 to stop Visual Studio warning */
src/PJ_labrd.c
Outdated
@@ -60,14 +60,18 @@ static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */ | |||
xy.y += Q->Cb * V1 - Q->Ca * V2 - Q->Cd * V3 + Q->Cc * V4; | |||
ps = Q->p0s + xy.y / Q->kRg; | |||
pe = ps + P->phi0 - Q->p0s; | |||
for ( i = 20; i; --i) { | |||
|
|||
V1 = Q->A * log(tan(M_FORTPI + .5 * pe)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't a do {} while ()
be the more elegant solution here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That didn't help. There are some regressions in cppcheck git HEAD. I finally just initialized t = 0.0 to make it happy, even if it isn't needed
src/PJ_labrd.c
Outdated
@@ -46,7 +46,7 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */ | |||
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */ | |||
LP lp = {0.0,0.0}; | |||
struct pj_opaque *Q = P->opaque; | |||
double x2, y2, V1, V2, V3, V4, t, t2, ps, pe, tpe, s; | |||
double x2, y2, V1, V2, V3, V4, t = 0.0, t2, ps, pe, tpe, s; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend tagging (with a comment) any unnecessary initializations performed to suppress a warning. Then a developer 5 years from now won't be left wondering whether the value t = 0.0 ever gets used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Comment added
No description provided.