several improvements to Path::getAbsolutePath()#6542
several improvements to Path::getAbsolutePath()#6542firewave merged 3 commits intocppcheck-opensource:mainfrom
Path::getAbsolutePath()#6542Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
This now crashes in Cygwin: |
|
Looks like it is caused by the static initialization order. So this requires https://trac.cppcheck.net/ticket/12080 to be fixed first. |
|
We could also make the cache in simplecpp optional. Nevertheless these caches are completely horrible and need to be implemented in a different way. |
71ef47a to
49daf24
Compare
|
The crash is fixed because the test fixtures are no longer global objects which depend on the initialization order. |
Path::getAbsolutePath()Path::getAbsolutePath()
| absolute_path = absolute; | ||
| free(absolute); | ||
| if (!filePath.empty() && !spath.empty() && absolute_path.empty() && !exists(spath)) | ||
| throw std::runtime_error("path '" + filePath + "' does not exist"); |
There was a problem hiding this comment.
This makes sure we do not get unexpected results. This needs an integration test which triggers this though (I am hoping one of the existing ones will fail so I can derive from that).
There was a problem hiding this comment.
The only case where this could happen is in loadVisualStudioProperties() and that code looks quite shifty and need some proper testing. As Path::isAbsolute() also needs some work that will probably happen in that context.
b62a0d9 to
fd971fa
Compare
I filed cppcheck-opensource/simplecpp#361 upstream. |
| char absolute[_MAX_PATH]; | ||
| if (_fullpath(absolute, filePath.c_str(), _MAX_PATH)) | ||
| absolute_path = absolute; | ||
| if (absolute_path.back() == '\\') |
There was a problem hiding this comment.
there is a good chance that absolute_path is empty right? don't call back() in that case.
There was a problem hiding this comment.
That would indeed be undefined: https://en.cppreference.com/w/cpp/string/basic_string/back - and we even report that. I wonder if that might exists in other parts of the code. We could probably be more aggressive about detecting that - maybe similar to a NULL dereference.
The _fullpath() call might need better errorhandling.
There was a problem hiding this comment.
That would indeed be undefined: https://en.cppreference.com/w/cpp/string/basic_string/back - and we even report that. I wonder if that might exists in other parts of the code. We could probably be more aggressive about detecting that - maybe similar to a NULL dereference.
This is not reported because it is in the _WIN32 code which we do not analyze in the CI. We should probably add analysis steps for files using those to the selfchecks.
There was a problem hiding this comment.
Fixed. I also added a bunch of missing test cases and TODOs.
I also filed https://trac.cppcheck.net/ticket/13158 about enhancing the selfcheck.
fd971fa to
290f233
Compare
| if (absolute) | ||
| absolute_path = absolute; | ||
| free(absolute); | ||
| if (!filePath.empty() && !spath.empty() && absolute_path.empty() && !exists(spath)) |
There was a problem hiding this comment.
we know that filePath is not empty. so condition !filePath.empty() && is redundant.
I am not sure shouldn't we use || instead of && here. each of those conditions look bad?
There was a problem hiding this comment.
Even though there is a preprocessor check that should be detected.
I will review the remaining conditions and add a comment about the intention.
There was a problem hiding this comment.
I filed https://trac.cppcheck.net/ticket/13178 about detecting this.
There was a problem hiding this comment.
I adjusted the check and added a comment.
290f233 to
fb1ddd7
Compare
..do not existgetAbsolutePath()if the given path does not exist