Skip to content
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

Merged
merged 1 commit into from
Feb 28, 2017

Conversation

rouault
Copy link
Member

@rouault rouault commented Feb 28, 2017

No description provided.

@rouault rouault force-pushed the cppcheck branch 3 times, most recently from fd35f0c to 3db75dd Compare February 28, 2017 00:20
@@ -85,7 +85,10 @@ static void Init() {
tolb = tol0 * tol2;
xthresh = 1000 * tol2;
degree = pi/180;
NaN = sqrt(-1.0);
{
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Contributor

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));
Copy link
Member

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?

Copy link
Member Author

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;
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Comment added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants