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

Some issues found by scan-build #238

Merged
merged 16 commits into from
Dec 2, 2019
Merged

Some issues found by scan-build #238

merged 16 commits into from
Dec 2, 2019

Conversation

Algunenano
Copy link
Contributor

Used: scan-build make

If you are interested I can try to address the rest of the issues.

@Algunenano Algunenano changed the title Some issues find by scan-build Some issues found by scan-build Oct 8, 2019
@Algunenano
Copy link
Contributor Author

Pending warnings:
image

@@ -6266,7 +6266,7 @@ extern "C" {
const Geometry* p)
{

double length;
double length = NAN;
Copy link
Member

@dbaston dbaston Oct 8, 2019

Choose a reason for hiding this comment

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

We recently got rid of the NAN macros, so if NAN is useful here maybe use std::numeric_limits<double>::quiet_NaN() or whatever it is? I don't think the default value is actually important because I don't think GEOSLength is capable of producing an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't using getLength(), it's using GEOSLength_r which can produce errors if the handle or the geometry are NULL.

I've used NAN here because length is then used as a denominator in a function. The other option would be to check the output of GEOSLength_r and return an error somehow in GEOSProjectNormalized_r, GEOSInterpolateNormalized_r; but I don't know what would a proper value be in that case (0?, NAN?).

Copy link
Member

Choose a reason for hiding this comment

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

Yes, better to check the return of GEOSLength_r and propagate the error value of GEOSProject_r / GEOSInterpolateNormalized_r.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking at the code it seems that the sane thing to do would be to return -1 in GEOSProjectNormalized_r (the return error for GEOSProject_r) and 0 in GEOSInterpolateNormalized_r (the return error for GEOSInterpolate_r), right?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that's what I was trying to say.

src/io/WKTReader.cpp Outdated Show resolved Hide resolved
scan-build warning:
DistanceOp.cpp:277:28: warning: Dereference of null smart pointer of type 'std::unique_ptr'
    const Coordinate& pt = ptLoc->getCoordinate();

Since the content of loc was moved but still used in the loop,
it might happen `!(minDistance <= terminateDistance))` that loc was
used in the next iteration where its contents were nullified
by the previous move.

By returning in the same function we let the compiler
understand that we are already done
Apparently is unable to see that nPts can't be 0
@Algunenano
Copy link
Contributor Author

There is still 3 warnings left. The idea is to first clean these warnings and then add a new CI target that runs scan-build so it's run automatically.

@@ -299,23 +299,23 @@ MinimumBoundingCircle::pointWitMinAngleWithX(std::vector<Coordinate>& pts, Coord
Coordinate
Copy link
Member

Choose a reason for hiding this comment

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

Was the dereference even necessary in the first place, or should the function just return const Coordinate* ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, in fact now that I'm looking at it there is a way less intrusive way to handle this which is to just initialize minAngPt to a pointer to the first element, instead of nullptr.

Copy link
Member

Choose a reason for hiding this comment

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

But why does this function need to return a copy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are absolutely right. All the other functions do the same, should I change the 3 of them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now that I look into it, this would involve major changes in the API, changing extremalPts to an array of references / pointers and so on, so I'd rather do it in a different PR and leave this one with the copy for now.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good. While you're in there, the other function arguments should probably be const Coordinate & instead of mutable...

scan-build points out that, under some circunstances, it'd possible
for minAngPt no never be set (thus being nullptr) and that would
mean dereferencing a NULL ptr when returning the object.
@dbaston
Copy link
Member

dbaston commented Oct 30, 2019

@Algunenano are you still working here, or should this branch be merged (I'll squash out the back-and-forth commits first, unless you want to)

@Algunenano
Copy link
Contributor Author

@Algunenano are you still working here, or should this branch be merged (I'll squash out the back-and-forth commits first, unless you want to)

I'm still working on it when I can. There are still a few (2-3?, I don't recall exactly) issues I want to tackle and then I want to try and add the check to the CI.

@dbaston dbaston added the WIP Work in progress, do not merge. label Oct 30, 2019
CoordinateOperation.cpp:50:12: warning: Called C++ object pointer is null
    return geometry->clone();
           ^~~~~~~~~~~~~~~~~
ShortCircuitedGeometryVisitor.cpp:40:13: warning: Forming reference to null pointer
            visit(*element);
            ^~~~~~~~~~~~~~~
@Algunenano
Copy link
Contributor Author

I'm currently working on 2 missing things:

  • Some warnings in ttmath, which I'm not sure how to fix it or ignore it. I've tried updating the library to its current trunk but the warnings are still there.
  • Create a build in Travis running with scan-build. Right now I'm fighting against C++11 flags, which for some reasons it's not getting automatically and the build fails.

@dbaston
Copy link
Member

dbaston commented Nov 8, 2019

  • Some warnings in ttmath, which I'm not sure how to fix it or ignore it. I've tried updating the library to its current trunk but the warnings are still there.

Yes, I also spent some time looking at how to conditionally disable some warnings in this header. It seemed like there should be a way to do it by getting CMake to treat it as a "system" header, but I didn't get it to work. For scan-build, does it make sense to just create a suppressions file?

  • Create a build in Travis running with scan-build. Right now I'm fighting against C++11 flags, which for some reasons it's not getting automatically and the build fails.

I think the longer-term vision is to use AzP, so you might try making the changes there instead.

@Algunenano
Copy link
Contributor Author

Yes, I also spent some time looking at how to conditionally disable some warnings in this header. It seemed like there should be a way to do it by getting CMake to treat it as a "system" header, but I didn't get it to work. For scan-build, does it make sense to just create a suppressions file?

I'll give a try to #pragma GCC system_header and see how it goes, that should get rid of all warnings related to that file and might help scan-build too.

I think the longer-term vision is to use AzP, so you might try making the changes there instead.

For now I'm using Travis because I already know it and had it activated in my fork, but I'll consider switching once I get everything working.

@Algunenano
Copy link
Contributor Author

scan-build appears to ignore my demands of using system_header, but t seems assigning default constructors to ttmath::Big members is enough to please it, so I'll go with that route instead.

@Algunenano
Copy link
Contributor Author

Ok, with this I get a clean build now and there should be a Travis task (https://travis-ci.com/libgeos/geos/jobs/254533462) that only passes if scan-build doesn't throw any warning.

@Algunenano
Copy link
Contributor Author

@dbaston I'd say this is ready for final review now. Let me know if I should improve anything to get it merged.

@strk strk merged commit a12ffb1 into libgeos:master Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WIP Work in progress, do not merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants