aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2011-09-14 01:34:46 +0400
committerIgor Pashev <pashev.igor@gmail.com>2011-09-14 01:34:46 +0400
commit74dedc49c70673da227651e6f15412445be4230b (patch)
treeb646de24ccc2631ab4145fc78deb1cb625790146
parent6047b3835a1b88932ab2140570e75baf7ffbfa3e (diff)
downloadbrainfuck-74dedc49c70673da227651e6f15412445be4230b.tar.gz
Fixed segfault
-rw-r--r--brainfuck.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/brainfuck.c b/brainfuck.c
index dc36340..d62c2a9 100644
--- a/brainfuck.c
+++ b/brainfuck.c
@@ -78,7 +78,7 @@ read_code()
if (n >= allocated)
{
- allocated <<= 1;
+ allocated *= 2;
code = (char *)realloc(code, allocated * sizeof(char));
}
code[n++] = '\0';
@@ -740,9 +740,16 @@ main(int argc, char **argv)
{
bf2c();
}
- else if (strcmp(print_as, "cow") == 0)
+ else if (print_as != NULL)
{
- bf2moo();
+ if (strcmp(print_as, "cow") == 0)
+ {
+ bf2moo();
+ }
+ else
+ {
+ fprintf(stderr, "Unknown argument to -p: %s\n", print_as);
+ }
}
else
{