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

Add a way for C/C++ code compiled as a part of a CodeQL test to detect it is being tested #9425

Open
gsingh93 opened this issue Jun 2, 2022 · 1 comment
Labels
C++ question Further information is requested

Comments

@gsingh93
Copy link
Contributor

gsingh93 commented Jun 2, 2022

It would be convenient if there was a way for C/C++ code that is being compiled as part of a CodeQL test to know that it's part of a CodeQL test. This could be done by defining some type of macro that is defined when compiling any test, i.e. __CODEQL_TEST__.

The reason this would be useful is that I could easily compile and run this code outside of a CodeQL test without making any code modifications. Currently I am doing something like this:

#ifndef REAL_COMPILATION

extern int stdin;
extern char* fgets(char*, int, int);
extern char* strchr(const char*, int);
char getchar();
int atoi(char*);
int printf(const char*, ...);
void* malloc(unsigned long);
void puts(const char*);

#else

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#endif

And then when I want to test my code outside of CodeQL I do gcc test.c -DREAL_COMPILATION=1. This works for me, but it would be more convenient if CodeQL itself defined some macro that I could check, instead of requiring me to specify this when I compile the code manually.

@gsingh93 gsingh93 added the question Further information is requested label Jun 2, 2022
@tausbn tausbn added the C++ label Jun 3, 2022
@tausbn
Copy link
Contributor

tausbn commented Jun 3, 2022

Thank you for your suggestion! I will pass it on to the C++ team.

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

No branches or pull requests

2 participants