![]() |
500 Ways to Cause An Error
If you have been following this forum for a long time you will remember the "famous" 500 Ways to Program the Numbers 1 Through 10! thread started by Sane.
I found it quite fun and a good way to encourage new members to participate because it didn't require a great deal of programming knowledge to contribute. So I propose that as a follow-up we all try to come up with as many creative or practical ways to cause an error in a program. It can be a compile-time or run-time error (or something else entirely), so long as it has the potential to wreak havoc. :twisted: Please list the language and a description of the error. (It is not necessary to list the reason it occurs if you don't know or can't be bothered.) I'll start: 1) C Description: This program causes a segmentation fault by attempting to overwrite data outside its allocated page. :
#include <stdio.h> |
Re: 500 Ways to Cause An Error
How about a boot sector overwrite :)
|
Re: 500 Ways to Cause An Error
2)
:
You can catch this one if you enable all warnings in GCC. With a default compile though, there are (surprisingly) no compile-time errors. As far as I can guess, x in main() ends up pointing to a random location in memory and a segfault results. I don't know enough about how GCC compiles code to know exactly what happens. |
Re: 500 Ways to Cause An Error
Titaniumdecoy's program may or may not crash depending on stack size, it didn't crash on mine machine:(
language: C Description: realloc could return NULL and overwrite the original pointer value, causing a seg fault later in the program :
#include<stdio.h> |
Re: 500 Ways to Cause An Error
4)
Languge: Perl It keeps on forking indefinitely. It's not really an error with perl, but it makes a hell of a fork bomb. :
sub keep_on_forking { |
Re: 500 Ways to Cause An Error
5) OCaml
:
(* Demonstrate the strong typing of OCaml. *)compiling a byte-code version (native compiler also available): :
$ ocamlc foo.ml -o foo |
Re: 500 Ways to Cause An Error
This will probably be my last one. I see it (and do it myself) so often that I thought it would be best. ;)
6) C :
What you'd expect to happen is that the parameter, x is set to point to the newly allocated memory. What actually happens is that a copy of the pointer is made, and the copy is what's assigned to. The x in main() remains set to NULL, and the code segfaults. |
Re: 500 Ways to Cause An Error
:
|
Re: 500 Ways to Cause An Error
Here is one I saw just today
c++ :
char* p; |
Re: 500 Ways to Cause An Error
9)
:
char string[32]; |
| All times are GMT -5. The time now is 4:11 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC