X Tutup
The Wayback Machine - https://web.archive.org/web/20220707002934/https://github.com/github/codeql/issues/9562
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

Regex doesn't work properly #9562

Open
MFaisalZaki opened this issue Jun 15, 2022 · 1 comment
Open

Regex doesn't work properly #9562

MFaisalZaki opened this issue Jun 15, 2022 · 1 comment
Labels
C++ question

Comments

@MFaisalZaki
Copy link

@MFaisalZaki MFaisalZaki commented Jun 15, 2022

I am trying to recognize #pragma pack directive for MSVC. Therefore, I have wrote this simple query:

import cpp

from PreprocessorDirective directive
where directive.getHead().regexpMatch("pack*")
select directive

to capture the following two pack pragmas in this sample:

#pragma pack(push, 1)
#include "my_header.h"
#pragma pack(pop)

However, after various tries with regexpMatch and matches the query cannot capture the proper pattern even though I have tried the same pattern using RegExr and it is working as expected.

@MFaisalZaki MFaisalZaki added the question label Jun 15, 2022
@hmakholm hmakholm added the C++ label Jun 15, 2022
@hmakholm
Copy link
Contributor

@hmakholm hmakholm commented Jun 15, 2022

Your regular expression should be "pack.*" -- that is, pack followed by zero or more arbitrary characters.
"pack*" would mean the that the text of the directive needs to be pac followed by zero or more copies k.

(It looks like you were trying to use filename globbing syntax rather than regular expressions).

You could also write .matches("pack%") if you prefer the more SQL-like pattern syntax that matches uses.

Finally, for general neatness, you'll probably want directive to have type PreprocessorPragma rather than PreprocessorDirective).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ question
Projects
None yet
Development

No branches or pull requests

2 participants
X Tutup