c-basic/warning.c

16 lines
525 B
C
Raw Normal View History

2022-11-24 23:00:34 +01:00
#include <stdio.h>
int main(){
char s[2];
2022-11-26 00:10:35 +01:00
/*
* The following line of code is unsafe. It writes up to 10 bytes into the char array 's', which is only
* 2 Bytes big. A Buffer Overflow can happen. I have chosen to keep that line, because i wanted a source
* file that produces a compiler warning when it is compiled. That is the true purpose of this file.
*
* a safe alternative would be: fgets(s, 2, stdin);
*/
fgets(s, 10, stdin); // UNSAFE
2022-11-24 23:00:34 +01:00
printf("%s\n",s);
return 0;
}