Skip to content

Instantly share code, notes, and snippets.

@kwannoel
Created April 11, 2021 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwannoel/b4e3d586737275b7a292d8e60f5df8a8 to your computer and use it in GitHub Desktop.
Save kwannoel/b4e3d586737275b7a292d8e60f5df8a8 to your computer and use it in GitHub Desktop.
Increment trigger until you see output upon program crash.
#include <stdio.h>
int main()
{
int *ip = NULL; //just a convenient way to crash a program :-)
int i, trigger;
printf("Trigger at (positive int): ");
scanf("%d", &trigger);
for(i = 0; ; i++) { // essentially an infinite loop
printf("%d", i%10);
if (i == trigger)
*ip = 123; //boom!
}
return 0;
}
@kwannoel
Copy link
Author

Observe that low trigger values do not output anything. This is because output is buffered. Only high values such as 10000, output gets written, because buffer size is filled.

Also \n causes buffer to flush.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment