◐ Shell
clean mode source ↗

Fix relative paths, again by Tal500 · Pull Request #418 · cppcheck-opensource/simplecpp

This manual test is the same isn't it?

daniel@laptop:~/cppchecksolutions/cppcheck$ mkdir system
daniel@laptop:~/cppchecksolutions/cppcheck$ touch system/header3.h
daniel@laptop:~/cppchecksolutions/cppcheck$ echo "#include <header3.h>" > test.c
daniel@laptop:~/cppchecksolutions/cppcheck$ gcc -E -Isystem test.c

gcc does not complain about a missing header3.h file.

I didn't notice that the file is actually being created, so the behavior you claimed is correct.
However, if you do the following next command you'd see that simplecpp detect this case correctly:

> ./simplecpp -Isystem test.c
(no output)

After debugging, I uploaded a fix now. The error was that the wchar to char conversion of the current directory was failing for some reason in windows 2019 release (a very weird bug, really don't know the true cause).
I found an easier implementation for current directory extraction in Windows in this codebase (path.cpp), so I stole this code and modified the implementation of currentDirectoryOSCalc():

static std::string currentDirectoryOSCalc() {
    const std::size_t size = 4096;
    char currentPath[size];

#ifndef _WIN32
    if (getcwd(currentPath, size) != nullptr)
#else
    if (_getcwd(currentPath, size) != nullptr)
#endif
        return std::string(currentPath);

    return "";
}

For debugging and verifying, I tried to create a pull request in my fork of cppcheck, to reproduce your checks. The checks looks very good now - Tal500/cppcheck#1

Sadly, I was unable to reproduce this weird behavior in simplecpp automated CI workflow, so while the logical test code is already covered by the python tests, the CI windows setup that reproduced it is not.

Please try to integrate it again.