Hello,
I am new on the cppcheck topic, and I am trying to understand how to write my own rules.
I have seen the addon part to write with python, but I would like to try the C++ part.
There is a link on the wiki on a documentation, but the link is broken : http://sourceforge.net/projects/cppcheck/files/Articles/writing-rules-3.pdf/download
Is there any documentation to help me start, some clue about the architecture, the tokens etc. ?
Thanks in advance and thank you for this tool!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Well currently the first check I want to try to implement is pretty straightforward.
I want to report an error when a call to the strtok function is done.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you for the entry point.
Is there an easiest way to know that the current token is a function call?
In the case of memsetZeroBytes I see that it test the name of the function and the number or arguments with numberOfArguments and if I look at the code of numberOfArguments I see that it test that the next token is a "("
I take a quick look at astutils but didn't manage to find another solution and don't see anything specifics in the ast dump file.
Just to be sure I am doing the more direct approach.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I have made some great progress on my customs errors.
I have a new question:
My check search method1 call, but there is multiple definition of method1 coming from various class.
So I need to find method1 from myClass
How I am supposed to find the inheritance of the token named method1 in the source that I am currently checking to test that it come from myClass?
I take a look at the function class but didn't find anything usefull
Thank you for you endless help Daniel!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I am new on the cppcheck topic, and I am trying to understand how to write my own rules.
I have seen the addon part to write with python, but I would like to try the C++ part.
There is a link on the wiki on a documentation, but the link is broken : http://sourceforge.net/projects/cppcheck/files/Articles/writing-rules-3.pdf/download
Is there any documentation to help me start, some clue about the architecture, the tokens etc. ?
Thanks in advance and thank you for this tool!
do you have some specific idea?
Well currently the first check I want to try to implement is pretty straightforward.
I want to report an error when a call to the strtok function is done.
yes that rule sounds pretty easy to implement. I guess you can look at
CheckFunctions::memsetZeroBytes()
.Thank you for the entry point.
Is there an easiest way to know that the current token is a function call?
In the case of memsetZeroBytes I see that it test the name of the function and the number or arguments with numberOfArguments and if I look at the code of numberOfArguments I see that it test that the next token is a "("
I take a quick look at astutils but didn't manage to find another solution and don't see anything specifics in the ast dump file.
Just to be sure I am doing the more direct approach.
in this case I would check if strtok is a library function:
It works like a charm, thank you.
Now I am trying to implement something harder.
The rules is : when you are calling a function named QueryInterface(arg1, arg2)
You should call arg2.Release() before the end the scope of arg2.
I try to do, based on code in checkfunctions.cpp :
at my great surprise lastParamTok return '('
The code I am parsing is :
pBS->QueryInterface(mkBSIntf::ClassId(), (void**)&PtrToBSIntf);
Is there a method for me to get PtrToBSIntf instead of '(' ?
Am I suppose to move on the ast starting from the '(' to find the variable name?
Yes. I recommend that you use astOperand1 and astOperand2. As you might have figured out a cast is in cppcheck AST a unary operator with 1 operand.
Last edit: Daniel Marjamäki 2021-10-21
Hello,
I have made some great progress on my customs errors.
I have a new question:
My check search method1 call, but there is multiple definition of method1 coming from various class.
So I need to find method1 from myClass
How I am supposed to find the inheritance of the token named method1 in the source that I am currently checking to test that it come from myClass?
I take a look at the function class but didn't find anything usefull
Thank you for you endless help Daniel!
not sure. I think something like this:
Function::functionScope() => Scope::functionOf() => class scope
I assume that the class declaration is seen.
Last edit: Daniel Marjamäki 2021-12-06