summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--AUTHORS1
-rw-r--r--src/codegen.c25
-rw-r--r--tools/mirb/mirb.c13
-rw-r--r--tools/mrbc/mrbc.c3
-rw-r--r--tools/mruby/mruby.c3
-rw-r--r--tools/xpcat/xpcat.c9
6 files changed, 32 insertions, 22 deletions
diff --git a/AUTHORS b/AUTHORS
index bba8b8a66..dc5d7a508 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -9,3 +9,4 @@ Original Authors "mruby developers" are:
Yuichiro MASUI
Masamitsu MURASE
Masaki Muranaka
+ Internet Initiative Japan Inc.
diff --git a/src/codegen.c b/src/codegen.c
index 49d53b1ea..799ec1500 100644
--- a/src/codegen.c
+++ b/src/codegen.c
@@ -511,9 +511,10 @@ for_body(codegen_scope *s, node *tree)
}
codegen(s, tree->cdr->cdr->car, VAL);
pop();
- c = s->iseq[s->pc-1];
- if (GET_OPCODE(c) != OP_RETURN || GETARG_B(c) != OP_R_NORMAL || s->pc == s->lastlabel) {
- genop_peep(s, MKOP_AB(OP_RETURN, cursp(), OP_R_NORMAL), NOVAL);
+ if (s->pc > 0) {
+ c = s->iseq[s->pc-1];
+ if (GET_OPCODE(c) != OP_RETURN || GETARG_B(c) != OP_R_NORMAL || s->pc == s->lastlabel)
+ genop_peep(s, MKOP_AB(OP_RETURN, cursp(), OP_R_NORMAL), NOVAL);
}
loop_pop(s, NOVAL);
scope_finish(s, idx);
@@ -593,14 +594,16 @@ lambda_body(codegen_scope *s, node *tree, int blk)
}
codegen(s, tree->cdr->car, VAL);
pop();
- c = s->iseq[s->pc-1];
- if (GET_OPCODE(c) != OP_RETURN || GETARG_B(c) != OP_R_NORMAL || s->pc == s->lastlabel) {
- if (s->nregs == 0) {
- genop(s, MKOP_A(OP_LOADNIL, 0));
- genop(s, MKOP_AB(OP_RETURN, 0, OP_R_NORMAL));
- }
- else {
- genop_peep(s, MKOP_AB(OP_RETURN, cursp(), OP_R_NORMAL), NOVAL);
+ if (s->pc > 0) {
+ c = s->iseq[s->pc-1];
+ if (GET_OPCODE(c) != OP_RETURN || GETARG_B(c) != OP_R_NORMAL || s->pc == s->lastlabel) {
+ if (s->nregs == 0) {
+ genop(s, MKOP_A(OP_LOADNIL, 0));
+ genop(s, MKOP_AB(OP_RETURN, 0, OP_R_NORMAL));
+ }
+ else {
+ genop_peep(s, MKOP_AB(OP_RETURN, cursp(), OP_R_NORMAL), NOVAL);
+ }
}
}
if (blk) {
diff --git a/tools/mirb/mirb.c b/tools/mirb/mirb.c
index d510f413b..502400c72 100644
--- a/tools/mirb/mirb.c
+++ b/tools/mirb/mirb.c
@@ -143,7 +143,9 @@ print_cmdline(int code_block_open)
int
main(void)
{
- char last_char, ruby_code[1024], last_code_line[1024];
+ char last_char;
+ char ruby_code[1024] = { 0 };
+ char last_code_line[1024] = { 0 };
int char_index;
mrbc_context *cxt;
struct mrb_parser_state *parser;
@@ -163,8 +165,6 @@ main(void)
cxt = mrbc_context_new(mrb);
cxt->capture_errors = 1;
- memset(ruby_code, 0, sizeof(*ruby_code));
- memset(last_code_line, 0, sizeof(*last_code_line));
while (TRUE) {
print_cmdline(code_block_open);
@@ -197,8 +197,7 @@ main(void)
strcat(ruby_code, last_code_line);
}
else {
- memset(ruby_code, 0, sizeof(*ruby_code));
- strcat(ruby_code, last_code_line);
+ strcpy(ruby_code, last_code_line);
}
}
@@ -238,8 +237,8 @@ main(void)
p(mrb, result);
}
}
- memset(ruby_code, 0, sizeof(*ruby_code));
- memset(ruby_code, 0, sizeof(*last_code_line));
+ ruby_code[0] = '\0';
+ last_code_line[0] = '\0';
mrb_parser_free(parser);
}
}
diff --git a/tools/mrbc/mrbc.c b/tools/mrbc/mrbc.c
index 94675c391..5382b90a8 100644
--- a/tools/mrbc/mrbc.c
+++ b/tools/mrbc/mrbc.c
@@ -70,8 +70,9 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
char *infile = NULL;
char *outfile = NULL;
char **origargv = argv;
+ static const struct _args args_zero = { 0 };
- memset(args, 0, sizeof(*args));
+ *args = args_zero;
args->ext = RITEBIN_EXT;
for (argc--,argv++; argc > 0; argc--,argv++) {
diff --git a/tools/mruby/mruby.c b/tools/mruby/mruby.c
index 2719bad01..444170270 100644
--- a/tools/mruby/mruby.c
+++ b/tools/mruby/mruby.c
@@ -57,8 +57,9 @@ static int
parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
{
char **origargv = argv;
+ static const struct _args args_zero = { 0 };
- memset(args, 0, sizeof(*args));
+ *args = args_zero;
for (argc--,argv++; argc > 0; argc--,argv++) {
char *item;
diff --git a/tools/xpcat/xpcat.c b/tools/xpcat/xpcat.c
index ce3d5854e..e39babcb5 100644
--- a/tools/xpcat/xpcat.c
+++ b/tools/xpcat/xpcat.c
@@ -26,8 +26,10 @@ main(int argc, char *argv[])
i++;
if (i < argc)
output = argv[i];
- else
+ else {
+ usage(argv[0]);
return EXIT_FAILURE;
+ }
}
}
@@ -40,7 +42,10 @@ main(int argc, char *argv[])
setbuf(outfile, NULL);
for (i = 1; i < argc; i++) {
- if (strcmp(argv[i], "-o") == 0) { i++; continue; }
+ if (strcmp(argv[i], "-o") == 0) {
+ i++;
+ continue;
+ }
infile = fopen(argv[i], "rb");
if (!infile) {