some C code
By i (Thu Dec 21, 2006 at 05:09:23 PM EST) ( all tags)
found this little snippet somewhere. audit it. is it safe? is there some input that will result in crash, er, undefined behaviour? i couldn't find any. can you?
#include <stdlib.h>
int main(int argc, char **argv)
{
int a, b;
if (argc != 3)
return 1;
a = strtol(argv[1], (char**)NULL, 10);
b = strtol(argv[2], (char**)NULL, 10);
return b ? a / b : 0;
}
oh, and i've got a job. starting Jan 02.
Update [2006-12-21 19:38:15 by i]:atoi is bad, using strtol instead. the question remains: is this code safe?
Full discussion: http://www.hulver.com/scoop/story/2006/12/21/17923/832
|