diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 2b2072c1f..6fb112cab 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -44,6 +44,10 @@ #include #endif +// The default template format is "gcc" +static const char GCC_TEMPLATE_FORMAT[] = "{file}:{line}:{column}: warning: {message} [{id}]\\n{code}"; +static const char GCC_TEMPLATE_LOCATION[] = "{file}:{line}:{column}: note: {info}\\n{code}"; + static void addFilesToList(const std::string& FileList, std::vector& PathNames) { // To keep things initially simple, if the file can't be opened, just be silent and move on. @@ -638,9 +642,8 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) } if (mSettings->templateFormat == "gcc") { - //_settings->templateFormat = "{file}:{line}: {severity}: {message}"; - mSettings->templateFormat = "{file}:{line}:{column}: warning: {message} [{id}]\\n{code}"; - mSettings->templateLocation = "{file}:{line}:{column}: note: {info}\\n{code}"; + mSettings->templateFormat = GCC_TEMPLATE_FORMAT; + mSettings->templateLocation = GCC_TEMPLATE_LOCATION; } else if (mSettings->templateFormat == "daca2") { mSettings->templateFormat = "{file}:{line}:{column}: {severity}: {message} [{id}]"; mSettings->templateLocation = "{file}:{line}:{column}: note: {info}"; @@ -648,6 +651,8 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) mSettings->templateFormat = "{file}({line}): {severity}: {message}"; else if (mSettings->templateFormat == "edit") mSettings->templateFormat = "{file} +{line}: {severity}: {message}"; + else if (mSettings->templateFormat == "cppcheck1") + mSettings->templateFormat = "{callstack}: ({severity}{inconclusive:, inconclusive}) {message}"; } else if (std::strcmp(argv[i], "--template-location") == 0 || @@ -883,6 +888,13 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) } } + // Default template format.. + if (mSettings->templateFormat.empty()) { + mSettings->templateFormat = GCC_TEMPLATE_FORMAT; + if (mSettings->templateLocation.empty()) + mSettings->templateLocation = GCC_TEMPLATE_LOCATION; + } + mSettings->project.ignorePaths(mIgnoredPaths); if (mSettings->force) @@ -1143,7 +1155,8 @@ void CmdLineParser::printHelp() " '{file}:{line},{severity},{id},{message}' or\n" " '{file}({line}):({severity}) {message}' or\n" " '{callstack} {message}'\n" - " Pre-defined templates: gcc, vs, edit.\n" + " Pre-defined templates: gcc, vs, edit, cppcheck1\n" + " The default format is 'gcc'.\n" " --template-location=''\n" " Format error message location. If this is not provided\n" " then no extra location info is shown.\n" diff --git a/samples/AssignmentAddressToInteger/out.txt b/samples/AssignmentAddressToInteger/out.txt index aa9b1b0a5..a34dcb96f 100644 --- a/samples/AssignmentAddressToInteger/out.txt +++ b/samples/AssignmentAddressToInteger/out.txt @@ -1 +1,3 @@ -[samples\AssignmentAddressToInteger\bad.c:3]: (portability) Assigning a pointer to an integer is not portable. +samples\AssignmentAddressToInteger\bad.c:3:0: warning: Assigning a pointer to an integer is not portable. [AssignmentAddressToInteger] + int a = p; +^ diff --git a/samples/arrayIndexOutOfBounds/out.txt b/samples/arrayIndexOutOfBounds/out.txt index 63ea20f96..a011c019a 100644 --- a/samples/arrayIndexOutOfBounds/out.txt +++ b/samples/arrayIndexOutOfBounds/out.txt @@ -1 +1,3 @@ -[samples\arrayIndexOutOfBounds\bad.c:7]: (error) Array 'a[2]' accessed at index 2, which is out of bounds. +samples\arrayIndexOutOfBounds\bad.c:7:6: warning: Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds] + a[2] = 0; + ^ diff --git a/samples/autoVariables/out.txt b/samples/autoVariables/out.txt index a5f001b2f..678bcaf50 100644 --- a/samples/autoVariables/out.txt +++ b/samples/autoVariables/out.txt @@ -1 +1,3 @@ -[samples\autoVariables\bad.c:4]: (error) Address of local auto-variable assigned to a function parameter. +samples\autoVariables\bad.c:4:5: warning: Address of local auto-variable assigned to a function parameter. [autoVariables] + *a = &b; + ^ diff --git a/samples/bufferAccessOutOfBounds/out.txt b/samples/bufferAccessOutOfBounds/out.txt index 5ec472f40..c09494c1f 100644 --- a/samples/bufferAccessOutOfBounds/out.txt +++ b/samples/bufferAccessOutOfBounds/out.txt @@ -1 +1,3 @@ -[samples\bufferAccessOutOfBounds\bad.c:6]: (error) Array 'a[2]' accessed at index 2, which is out of bounds. +samples\bufferAccessOutOfBounds\bad.c:6:10: warning: Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds] + a[i] = 0; + ^ diff --git a/samples/erase/out.txt b/samples/erase/out.txt index 0cf04d01b..b36e7a0e3 100644 --- a/samples/erase/out.txt +++ b/samples/erase/out.txt @@ -1 +1,24 @@ -[samples\erase\bad.cpp:9] -> [samples\erase\bad.cpp:10] -> [samples\erase\bad.cpp:10] -> [samples\erase\bad.cpp:9] -> [samples\erase\bad.cpp:11] -> [samples\erase\bad.cpp:4] -> [samples\erase\bad.cpp:9]: (error) Using iterator to local container 'items' that may be invalid. +samples\erase\bad.cpp:9:32: warning: Using iterator to local container 'items' that may be invalid. [invalidContainer] + for (iter = items.begin(); iter != items.end(); ++iter) { + ^ +samples\erase\bad.cpp:9:17: note: Iterator to container is created here. + for (iter = items.begin(); iter != items.end(); ++iter) { + ^ +samples\erase\bad.cpp:10:19: note: Assuming condition is true. + if (*iter == 2) { + ^ +samples\erase\bad.cpp:10:19: note: Assuming condition is true. + if (*iter == 2) { + ^ +samples\erase\bad.cpp:9:37: note: Assuming condition is true. + for (iter = items.begin(); iter != items.end(); ++iter) { + ^ +samples\erase\bad.cpp:11:13: note: After calling 'erase', iterators or references to the container's data may be invalid . + items.erase(iter); + ^ +samples\erase\bad.cpp:4:22: note: Variable created here. + std::vector items; + ^ +samples\erase\bad.cpp:9:32: note: Using iterator to local container 'items' that may be invalid. + for (iter = items.begin(); iter != items.end(); ++iter) { + ^ diff --git a/samples/memleak/out.txt b/samples/memleak/out.txt index 7fd408c2f..e69de29bb 100644 --- a/samples/memleak/out.txt +++ b/samples/memleak/out.txt @@ -1 +0,0 @@ -[samples\memleak\bad.c:8]: (error) Memory leak: a diff --git a/samples/outOfBounds/out.txt b/samples/outOfBounds/out.txt index 522b93105..4432d9207 100644 --- a/samples/outOfBounds/out.txt +++ b/samples/outOfBounds/out.txt @@ -1 +1,3 @@ -[samples\outOfBounds\bad.c:5]: (error) Buffer is accessed out of bounds: str +samples\outOfBounds\bad.c:5:12: warning: Buffer is accessed out of bounds: str [bufferAccessOutOfBounds] + strcpy(str, "0123456789abcdef"); + ^ diff --git a/samples/resourceLeak/out.txt b/samples/resourceLeak/out.txt index 2efee2b22..84c63008c 100644 --- a/samples/resourceLeak/out.txt +++ b/samples/resourceLeak/out.txt @@ -1 +1,3 @@ -[samples\resourceLeak\bad.c:8]: (error) Resource leak: a +samples\resourceLeak\bad.c:8:5: warning: Resource leak: a [resourceLeak] + return 0; + ^ diff --git a/samples/syntaxError/out.txt b/samples/syntaxError/out.txt index 2617f34bf..d07934d38 100644 --- a/samples/syntaxError/out.txt +++ b/samples/syntaxError/out.txt @@ -1 +1,3 @@ -[samples\syntaxError\bad.c:2]: (error) Unmatched '{'. Configuration: ''. +samples\syntaxError\bad.c:2:1: warning: Unmatched '{'. Configuration: ''. [syntaxError] + +^