Suppose that you are give a single C source file
, that contains a max. of 300 lines of code.
Suppose also that the file, while implementing several functions, DOES NOT contain the character '#' in it (meaning, there are NO #include
statmements, and no other statements that have '#' in the file).
My question is, does the above guarantee that the file does not do any I/O? does it guarantee that the file will not be able to (say) erase the contents of the hard drive, or do other fishy things?
(I am supposed to get 100-200 single C
files, that (as mentioned) do not include the char #
in them. I was asked to write a simple program that will programmatically check if a single C source file
with no #
is potentially involved in I/O, accessing to the network etc).
Given the fact that no statements with #
are allowed -- what is the WORST code a coder can include in such a C
file to potentially damage the system of the one who runs it?
I know that no check will yield 100% accuracy -- but am interested at least to do some basic checks that will raise a red flag if some expressions / keywords are found. Any ideas of what to look for?
Address in CIf you have a variable var in your program, &var will give you its address in the memory. We have used address numerous times while using the scanf() function. scanf("%d", &var); Here, the value entered by the user is stored in the address of var variable. Let's take a working example.
Archive libraries (. a) are statically linked i.e when you compile your program with -c option in gcc. So, if there's any change in library, you need to compile and build your code again.
An O file is a compiled C program object. Some C compilers create O files during the executable (. EXE) creation process. O files themselves are typically not executable. When compiling a C program, compilers first transform all the program's source code files into compiled object files.
For C File I/O you need to use a FILE pointer, which will let the program keep track of the file being accessed. For Example: FILE *fp; To open a file you need to use the fopen function, which returns a FILE pointer.
No, it can't guarantee that. You can produce the code where all includes and macros are expanded, and you can make it into a single huge file, then compile it... that file, won't contain any preprocessor directive, though it can do anything usually C can do on a system.
If the original coder were to include inline assembly, they could do pretty much anything they liked, without importing any libraries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With