Skip to content

Instantly share code, notes, and snippets.

@gsora
Created June 20, 2014 18:21
Show Gist options
  • Select an option

  • Save gsora/6d8cdaf82519c47fae19 to your computer and use it in GitHub Desktop.

Select an option

Save gsora/6d8cdaf82519c47fae19 to your computer and use it in GitHub Desktop.
This is why gets() is unsafe
#include <stdio.h>
#define BUF 5
int main(void) {
int a = 2;
char word[BUF];
printf("Declaread an integer a = 2, and a string.\nThis is where the gets kicks in.\nThe string where gets() will write is big 5, try to write someting > 5 and see what appends!\ngets: ");
gets(word);
printf("\nString:%s\na = %d\n", word, a);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment