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

C: preprocessor branches truncated to first line #18842

Open
randomdude opened this issue Feb 23, 2025 · 1 comment
Open

C: preprocessor branches truncated to first line #18842

randomdude opened this issue Feb 23, 2025 · 1 comment
Labels
question Further information is requested

Comments

@randomdude
Copy link

Hi all. I'm seeing some unexpected behavior from CodeQL when I process C preprocessor branches that span multiple lines.

For example, if I scan the following C file:

#if defined(FOO) || \
     defined(BAR)
#endif

with the following query:

from PreprocessorBranchDirective pbd select pbd, pbd.toString()

I see the output:

"foo","foo","error","#if defined(FOO) || \","/a.c","1","1","1","21"
"foo","foo","error","#endif","/a.c","3","1","3","6"

I expected to see the entire multiline preprocessor condition in the output of the .toString(), rather than just the first line - but when I went to file this bug, I realised this is not specified anywhere as correct behavior (as far as I can see), and so this may be expected behavior. However, if we ignore that maybe-issue, there is still a second issue - the location information appears to be incorrect, stating that the preprocessor condition ends at line 1 column 21, while it actually ends on line 2.

Finally - it may be that the CSV output is malformed, as the terminating quote is prefixed by a backslash.

Hope this is helpful! For your extra context, I found this while scanning the Linux kernel, so it seems this is a common code pattern, as opposed to an infrequently-seen corner case.

@randomdude randomdude added the question Further information is requested label Feb 23, 2025
@jketema
Copy link
Contributor

jketema commented Feb 24, 2025

Hi @randomdude,

This is a known issue. I've added a link to this issue to hte internal issue that tracks this.

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

No branches or pull requests

2 participants