test.c

void fun(){
        printf("int main char");
    }

    int main()
    {
        printf("int main int");
    }

Im giving the command like this "run.sh cpd --minimum-tokens 5 --files /opt/test.c --language c" and the output is as follows :

Found a 2 line (5 tokens) duplication in the following files:
Starting at line 1 of /opt/test.c
Starting at line 5 of /opt/test.c

void fun(){
    printf("int main char ");

Even if there is no duplication, it is telling the code is duplicated because of minimum tokens. Is there any way to specify the command without minimum tokens flag.

void fun(){
    printf("int main int");
}

int main(){
    printf("int main int");
}

I specified the command like this "run.sh cpd --minimum-tokens 9 --files /opt/test.c --language c" the output is as follows:

  Added /opt/test.c <--- (No line duplication reported by tool)

This is because I specified the token value greater than the required token value which is 8. In the above case even if there is a duplicated code the tool is not returning any duplicated code.

So how to conclude on Min token size in such scenario in order to get correct duplication of code

I took a look at this old thing and there's a book and more out there. https://pmdapplied.com/

What I see is something that looks to have no active updates for about 5 years so this is a tool and like any tool of this ilk, once in a while you find someone thinking it does "this." A few others may think it's a panacea.

Don't get me wrong I like automated code inspection but there are folk that want to make it a rule or a gauntlet thou shall pass. (or not.) For me I'll get by with turning all the warnings on with a simple -wall.

Honestly, in 35 years of C and C++ software development professionally, I have never seen such an error. What compiler (and version) are you using?

gcc compiler 4.4.7 version.
CPD-PMD version is 5.4.1

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.