jplag / JPlag

State-of-the-Art Software Plagiarism & Collusion Detection
https://jplag.github.io/JPlag/
GNU General Public License v3.0
1.37k stars 312 forks source link

C++ parsing error messages #1780

Open smu-sc-gj opened 4 months ago

smu-sc-gj commented 4 months ago

Hi all,

A group of students suspected of working together produced code which compiles, but crashes 5.0 and causes errors on 2.12.1 (which I happened to still have on my machine).

The offending code:

 if (evt.keysym.sym == 'lmb')

The error on 5.0 is:

failed to parse 'projectName_XXXX/Name.cpp'Cannot invoke "de.jplag.cpp.grammar.CPP14Parser$PointerDeclaratorContext.noPointerDeclarator()" because the return value of "de.jplag.cpp.grammar.CPP14Parser$DeclaratorContext.pointerDeclaParsing Submissions    33% [========                 ] 1/3 (0:00:02 / 0:00:04)

The error on 2.12.1 is:

[projectName_XXXX]
  Scanning Error in 'src/Name.cpp':
  Lexical error at line 430, column 29.  Encountered: "m" (109), after : "\'l"

I used this error message to modify the line so it would parse and I now have reports from both. The error message from the older version is much easier to read and allows for exploration, the 5.0 error message less so.

I appreciate this needs further investigation with the latest version etc. I'll try to create a MWE for this when I have more time.

TwoOfTwelve commented 3 months ago

I've tried to replicate the issue using the following code:

void main() {
    if (evt.keysym.sym == 'lmb') {
    }
}

JPlag was able to process this without any problem, so I guess it depends on the surrounding code.

Do you have the option of sending the entire file or can you create a short example that encounters the error?

smu-sc-gj commented 2 months ago

While the original code is only a few files, there were some really big dependencies. The relevant one here being Ogre (the evt.keysym.sym comes from OgreBites. I've managed to re-create the issue with the following code:

#include <iostream>
#include <stdlib.h>

typedef int Keycode;

struct Keysym {
    Keycode sym;
    unsigned short mod;
};

struct KeyboardEvent {
    int type;
    Keysym keysym;
    unsigned char repeat;
};

bool keyProcessing(const KeyboardEvent& evt)
{
    std::cout << "Processing Key" << std::endl;

    if(evt.keysym.sym == 'w')
    {
        std::cout << "W" << std::endl;
    }

    /* I know this doesn't make sense ... but it's 
       what they original code was trying to do. */

    if(evt.keysym.sym == 'lmb')
    {
        std::cout << "Left Mouse Button" << std::endl;
    }

    return true;
}

int main(int argc, char** argv) 
{
  KeyboardEvent test;
  test.keysym.sym = 'w';

  keyProcessing(test);

  exit(EXIT_SUCCESS);
}

I created three copies of this file as a sample.

0 submissions parsed successfully! 3 parser errors!

Error: Not enough valid submissions! (only 0 are valid): [one.cpp] Scanning Error in 'one.cpp': Lexical error at line 29, column 28. Encountered: "m" (109), after : "\'l"

[three.cpp] Scanning Error in 'three.cpp': Lexical error at line 29, column 28. Encountered: "m" (109), after : "\'l"

[two.cpp] Scanning Error in 'two.cpp': Lexical error at line 29, column 28. Encountered: "m" (109), after : "\'l"


I hope this helps!
tsaglam commented 2 months ago
* Latest version (5.1.0) language set to `cpp`, I have a note that says this only works if the code is C++14 compatible throughout, the samples are but I'm not sure the student submission are.

Seems to work with the cpp language module.

* Latest version (5.1.0) with language set to `c`:

This language module is the former c/c++ module from the JPlag legacy version. We still provide it with JPlag, however we are not actively working on it. If anyone wants to provide a fix here, feel free to create a PR.