-
Notifications
You must be signed in to change notification settings - Fork 347
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
Conversation
Remove use after move semantics (in the asserts).
GEOSLength_r might not set length, and it's used in the next call
capi/geos_ts_c.cpp
Outdated
| @@ -6266,7 +6266,7 @@ extern "C" { | |||
| const Geometry* p) | |||
| { | |||
|
|
|||
| double length; | |||
| double length = NAN; | |||
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.
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.
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.
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?).
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.
Yes, better to check the return of GEOSLength_r and propagate the error value of GEOSProject_r / GEOSInterpolateNormalized_r.
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.
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?
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.
Yes, that's what I was trying to say.
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
|
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 | |||
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.
Was the dereference even necessary in the first place, or should the function just return const Coordinate* ?
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.
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.
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.
But why does this function need to return a copy?
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.
You are absolutely right. All the other functions do the same, should I change the 3 of them?
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.
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.
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.
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.
|
@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. |
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);
^~~~~~~~~~~~~~~
|
I'm currently working on 2 missing things:
|
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 think the longer-term vision is to use AzP, so you might try making the changes there instead. |
I'll give a try to
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. |
|
scan-build appears to ignore my demands of using |
|
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. |
|
@dbaston I'd say this is ready for final review now. Let me know if I should improve anything to get it merged. |

Used:
scan-build makeIf you are interested I can try to address the rest of the issues.