Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse error for C code #275

Closed
DrewDennison opened this issue Mar 9, 2020 · 6 comments
Closed

parse error for C code #275

DrewDennison opened this issue Mar 9, 2020 · 6 comments
Assignees
Labels
alpha Relates to an experimental feature bug Something isn't working lang:c user:external requested by someone outside of r2c

Comments

@DrewDennison
Copy link
Member

https://sgrep.live/Kl6

//low-end processors are slow on division
if (di->block_size == 1<<6 ){ //sha256
  nblocks = len >> 6;
  nbytes = len & 0xFFFFffC0;
} else if(di->block_size == 1<<7 ){ //sha512
  nblocks = len >> 7;
  nbytes = len & 0xFFFFff80;
} else {
  nblocks = len / di->block_size;
  nbytes = nblocks * di->block_size;
}

results in

{
  "matches": [],
  "errors": [
    {
      "check_id": "LexicalError",
      "path": "NO FILE INFO YET",
      "start": { "line": -1, "col": 0 },
      "end": { "line": -1, "col": 1 },
      "extra": {
        "message": "Lexical error: unrecognised symbol, in token rule:�",
        "line": "NO LINE"
      }
    }
  ]
}
@DrewDennison DrewDennison added bug Something isn't working user:external requested by someone outside of r2c lang:c labels Mar 9, 2020
@DrewDennison
Copy link
Member Author

@aryx do you agree this is a bug? Can we figure out if this is a <1 hour fix or something more

@dlukeomalley
Copy link
Member

@DrewDennison Following up, still affecting you?

@dgryski
Copy link

dgryski commented Jul 16, 2020

This is still an issue. I still get the following error with 0.15.0 running a simple query against the repo github.com/h2o/h2o.

~/go/src/github.com/h2o/h2o $ semgrep -l c -e 'if ($X , $Y) { ... }'
Traceback (most recent call last):
  File "/usr/local/bin/semgrep", line 33, in <module>
    sys.exit(load_entry_point('semgrep==0.15.0', 'console_scripts', 'semgrep')())
  File "/usr/local/Cellar/semgrep/0.15.0/libexec/lib/python3.8/site-packages/semgrep/__main__.py", line 11, in main
    cli()
  File "/usr/local/Cellar/semgrep/0.15.0/libexec/lib/python3.8/site-packages/semgrep/cli.py", line 322, in cli
    semgrep.semgrep_main.main(
  File "/usr/local/Cellar/semgrep/0.15.0/libexec/lib/python3.8/site-packages/semgrep/semgrep_main.py", line 343, in main
    semgrep_errors = [e.into_semgrep_error() for e in semgrep_core_errors]
  File "/usr/local/Cellar/semgrep/0.15.0/libexec/lib/python3.8/site-packages/semgrep/semgrep_main.py", line 343, in <listcomp>
    semgrep_errors = [e.into_semgrep_error() for e in semgrep_core_errors]
  File "/usr/local/Cellar/semgrep/0.15.0/libexec/lib/python3.8/site-packages/semgrep/core_exception.py", line 69, in into_semgrep_error
    with open(self._path, errors="replace") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'NO FILE INFO YET'
~/go/src/github.com/h2o/h2o $

@dgryski
Copy link

dgryski commented Jul 16, 2020

Here's the smallest reproducer I could find.

int bt1_pop64(int x) { return  0xFllu; }

The C parser doesn't like the llu suffix.

@aryx
Copy link
Collaborator

aryx commented Jul 22, 2020

@DrewDennison trying https://semgrep.live/Kl6 gives just "semgrep got an error" but I can't find a way to display the error.
Is it normal?

@ievans
Copy link
Member

ievans commented Aug 4, 2021

https://semgrep.dev/s/ZkEw works now! In the original snippet, there was an invalid whitespace character at the start of nblocks = len >> 6; that caused the parser to fail (it caused a real C compiler to fail too).

@ievans ievans closed this as completed Aug 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
alpha Relates to an experimental feature bug Something isn't working lang:c user:external requested by someone outside of r2c
Development

No branches or pull requests

6 participants