Commit ff96e759 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

vbscript: Use 0 as invalid instruction offset.

parent 49e1a1a5
...@@ -148,7 +148,7 @@ static unsigned push_instr(compile_ctx_t *ctx, vbsop_t op) ...@@ -148,7 +148,7 @@ static unsigned push_instr(compile_ctx_t *ctx, vbsop_t op)
new_instr = heap_realloc(ctx->code->instrs, ctx->instr_size*2*sizeof(instr_t)); new_instr = heap_realloc(ctx->code->instrs, ctx->instr_size*2*sizeof(instr_t));
if(!new_instr) if(!new_instr)
return -1; return 0;
ctx->code->instrs = new_instr; ctx->code->instrs = new_instr;
ctx->instr_size *= 2; ctx->instr_size *= 2;
...@@ -163,7 +163,7 @@ static HRESULT push_instr_int(compile_ctx_t *ctx, vbsop_t op, LONG arg) ...@@ -163,7 +163,7 @@ static HRESULT push_instr_int(compile_ctx_t *ctx, vbsop_t op, LONG arg)
unsigned ret; unsigned ret;
ret = push_instr(ctx, op); ret = push_instr(ctx, op);
if(ret == -1) if(!ret)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
instr_ptr(ctx, ret)->arg1.lng = arg; instr_ptr(ctx, ret)->arg1.lng = arg;
...@@ -175,7 +175,7 @@ static HRESULT push_instr_uint(compile_ctx_t *ctx, vbsop_t op, unsigned arg) ...@@ -175,7 +175,7 @@ static HRESULT push_instr_uint(compile_ctx_t *ctx, vbsop_t op, unsigned arg)
unsigned ret; unsigned ret;
ret = push_instr(ctx, op); ret = push_instr(ctx, op);
if(ret == -1) if(!ret)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
instr_ptr(ctx, ret)->arg1.uint = arg; instr_ptr(ctx, ret)->arg1.uint = arg;
...@@ -187,7 +187,7 @@ static HRESULT push_instr_addr(compile_ctx_t *ctx, vbsop_t op, unsigned arg) ...@@ -187,7 +187,7 @@ static HRESULT push_instr_addr(compile_ctx_t *ctx, vbsop_t op, unsigned arg)
unsigned ret; unsigned ret;
ret = push_instr(ctx, op); ret = push_instr(ctx, op);
if(ret == -1) if(!ret)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
instr_ptr(ctx, ret)->arg1.uint = arg; instr_ptr(ctx, ret)->arg1.uint = arg;
...@@ -204,7 +204,7 @@ static HRESULT push_instr_str(compile_ctx_t *ctx, vbsop_t op, const WCHAR *arg) ...@@ -204,7 +204,7 @@ static HRESULT push_instr_str(compile_ctx_t *ctx, vbsop_t op, const WCHAR *arg)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
instr = push_instr(ctx, op); instr = push_instr(ctx, op);
if(instr == -1) if(!instr)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
instr_ptr(ctx, instr)->arg1.str = str; instr_ptr(ctx, instr)->arg1.str = str;
...@@ -221,7 +221,7 @@ static HRESULT push_instr_double(compile_ctx_t *ctx, vbsop_t op, double arg) ...@@ -221,7 +221,7 @@ static HRESULT push_instr_double(compile_ctx_t *ctx, vbsop_t op, double arg)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
instr = push_instr(ctx, op); instr = push_instr(ctx, op);
if(instr == -1) if(!instr)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
*d = arg; *d = arg;
...@@ -264,7 +264,7 @@ static HRESULT push_instr_bstr(compile_ctx_t *ctx, vbsop_t op, const WCHAR *arg) ...@@ -264,7 +264,7 @@ static HRESULT push_instr_bstr(compile_ctx_t *ctx, vbsop_t op, const WCHAR *arg)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
instr = push_instr(ctx, op); instr = push_instr(ctx, op);
if(instr == -1) if(!instr)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
instr_ptr(ctx, instr)->arg1.bstr = bstr; instr_ptr(ctx, instr)->arg1.bstr = bstr;
...@@ -281,7 +281,7 @@ static HRESULT push_instr_bstr_uint(compile_ctx_t *ctx, vbsop_t op, const WCHAR ...@@ -281,7 +281,7 @@ static HRESULT push_instr_bstr_uint(compile_ctx_t *ctx, vbsop_t op, const WCHAR
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
instr = push_instr(ctx, op); instr = push_instr(ctx, op);
if(instr == -1) if(!instr)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
instr_ptr(ctx, instr)->arg1.bstr = bstr; instr_ptr(ctx, instr)->arg1.bstr = bstr;
...@@ -394,7 +394,7 @@ static HRESULT compile_unary_expression(compile_ctx_t *ctx, unary_expression_t * ...@@ -394,7 +394,7 @@ static HRESULT compile_unary_expression(compile_ctx_t *ctx, unary_expression_t *
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
return push_instr(ctx, op) == -1 ? E_OUTOFMEMORY : S_OK; return push_instr(ctx, op) ? S_OK : E_OUTOFMEMORY;
} }
static HRESULT compile_binary_expression(compile_ctx_t *ctx, binary_expression_t *expr, vbsop_t op) static HRESULT compile_binary_expression(compile_ctx_t *ctx, binary_expression_t *expr, vbsop_t op)
...@@ -409,7 +409,7 @@ static HRESULT compile_binary_expression(compile_ctx_t *ctx, binary_expression_t ...@@ -409,7 +409,7 @@ static HRESULT compile_binary_expression(compile_ctx_t *ctx, binary_expression_t
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
return push_instr(ctx, op) == -1 ? E_OUTOFMEMORY : S_OK; return push_instr(ctx, op) ? S_OK : E_OUTOFMEMORY;
} }
static HRESULT compile_expression(compile_ctx_t *ctx, expression_t *expr) static HRESULT compile_expression(compile_ctx_t *ctx, expression_t *expr)
...@@ -428,7 +428,7 @@ static HRESULT compile_expression(compile_ctx_t *ctx, expression_t *expr) ...@@ -428,7 +428,7 @@ static HRESULT compile_expression(compile_ctx_t *ctx, expression_t *expr)
case EXPR_DOUBLE: case EXPR_DOUBLE:
return push_instr_double(ctx, OP_double, ((double_expression_t*)expr)->value); return push_instr_double(ctx, OP_double, ((double_expression_t*)expr)->value);
case EXPR_EMPTY: case EXPR_EMPTY:
return push_instr(ctx, OP_empty) != -1 ? S_OK : E_OUTOFMEMORY; return push_instr(ctx, OP_empty) ? S_OK : E_OUTOFMEMORY;
case EXPR_EQUAL: case EXPR_EQUAL:
return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_equal); return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_equal);
case EXPR_EQV: case EXPR_EQV:
...@@ -450,7 +450,7 @@ static HRESULT compile_expression(compile_ctx_t *ctx, expression_t *expr) ...@@ -450,7 +450,7 @@ static HRESULT compile_expression(compile_ctx_t *ctx, expression_t *expr)
case EXPR_LTEQ: case EXPR_LTEQ:
return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_lteq); return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_lteq);
case EXPR_ME: case EXPR_ME:
return push_instr(ctx, OP_me) != -1 ? S_OK : E_OUTOFMEMORY; return push_instr(ctx, OP_me) ? S_OK : E_OUTOFMEMORY;
case EXPR_MEMBER: case EXPR_MEMBER:
return compile_member_expression(ctx, (member_expression_t*)expr, TRUE); return compile_member_expression(ctx, (member_expression_t*)expr, TRUE);
case EXPR_MOD: case EXPR_MOD:
...@@ -466,9 +466,9 @@ static HRESULT compile_expression(compile_ctx_t *ctx, expression_t *expr) ...@@ -466,9 +466,9 @@ static HRESULT compile_expression(compile_ctx_t *ctx, expression_t *expr)
case EXPR_NOT: case EXPR_NOT:
return compile_unary_expression(ctx, (unary_expression_t*)expr, OP_not); return compile_unary_expression(ctx, (unary_expression_t*)expr, OP_not);
case EXPR_NOTHING: case EXPR_NOTHING:
return push_instr(ctx, OP_nothing) != -1 ? S_OK : E_OUTOFMEMORY; return push_instr(ctx, OP_nothing) ? S_OK : E_OUTOFMEMORY;
case EXPR_NULL: case EXPR_NULL:
return push_instr(ctx, OP_null) != -1 ? S_OK : E_OUTOFMEMORY; return push_instr(ctx, OP_null) ? S_OK : E_OUTOFMEMORY;
case EXPR_OR: case EXPR_OR:
return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_or); return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_or);
case EXPR_STRING: case EXPR_STRING:
...@@ -500,7 +500,7 @@ static HRESULT compile_if_statement(compile_ctx_t *ctx, if_statement_t *stat) ...@@ -500,7 +500,7 @@ static HRESULT compile_if_statement(compile_ctx_t *ctx, if_statement_t *stat)
return hres; return hres;
cnd_jmp = push_instr(ctx, OP_jmp_false); cnd_jmp = push_instr(ctx, OP_jmp_false);
if(cnd_jmp == -1) if(!cnd_jmp)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
hres = compile_statement(ctx, stat->if_stat); hres = compile_statement(ctx, stat->if_stat);
...@@ -525,7 +525,7 @@ static HRESULT compile_if_statement(compile_ctx_t *ctx, if_statement_t *stat) ...@@ -525,7 +525,7 @@ static HRESULT compile_if_statement(compile_ctx_t *ctx, if_statement_t *stat)
return hres; return hres;
cnd_jmp = push_instr(ctx, OP_jmp_false); cnd_jmp = push_instr(ctx, OP_jmp_false);
if(cnd_jmp == -1) if(!cnd_jmp)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
hres = compile_statement(ctx, elseif_decl->stat); hres = compile_statement(ctx, elseif_decl->stat);
...@@ -563,7 +563,7 @@ static HRESULT compile_while_statement(compile_ctx_t *ctx, while_statement_t *st ...@@ -563,7 +563,7 @@ static HRESULT compile_while_statement(compile_ctx_t *ctx, while_statement_t *st
return hres; return hres;
jmp_end = push_instr(ctx, stat->stat.type == STAT_UNTIL ? OP_jmp_true : OP_jmp_false); jmp_end = push_instr(ctx, stat->stat.type == STAT_UNTIL ? OP_jmp_true : OP_jmp_false);
if(jmp_end == -1) if(!jmp_end)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
prev_label = ctx->while_end_label; prev_label = ctx->while_end_label;
...@@ -637,7 +637,7 @@ static HRESULT compile_forto_statement(compile_ctx_t *ctx, forto_statement_t *st ...@@ -637,7 +637,7 @@ static HRESULT compile_forto_statement(compile_ctx_t *ctx, forto_statement_t *st
return hres; return hres;
instr = push_instr(ctx, OP_assign_ident); instr = push_instr(ctx, OP_assign_ident);
if(instr == -1) if(!instr)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
instr_ptr(ctx, instr)->arg1.bstr = identifier; instr_ptr(ctx, instr)->arg1.bstr = identifier;
...@@ -645,7 +645,7 @@ static HRESULT compile_forto_statement(compile_ctx_t *ctx, forto_statement_t *st ...@@ -645,7 +645,7 @@ static HRESULT compile_forto_statement(compile_ctx_t *ctx, forto_statement_t *st
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
if(push_instr(ctx, OP_val) == -1) if(!push_instr(ctx, OP_val))
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
if(stat->step_expr) { if(stat->step_expr) {
...@@ -653,7 +653,7 @@ static HRESULT compile_forto_statement(compile_ctx_t *ctx, forto_statement_t *st ...@@ -653,7 +653,7 @@ static HRESULT compile_forto_statement(compile_ctx_t *ctx, forto_statement_t *st
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
if(push_instr(ctx, OP_val) == -1) if(!push_instr(ctx, OP_val))
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
}else { }else {
hres = push_instr_int(ctx, OP_short, 1); hres = push_instr_int(ctx, OP_short, 1);
...@@ -667,7 +667,7 @@ static HRESULT compile_forto_statement(compile_ctx_t *ctx, forto_statement_t *st ...@@ -667,7 +667,7 @@ static HRESULT compile_forto_statement(compile_ctx_t *ctx, forto_statement_t *st
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
step_instr = push_instr(ctx, OP_step); step_instr = push_instr(ctx, OP_step);
if(step_instr == -1) if(!step_instr)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
instr_ptr(ctx, step_instr)->arg2.bstr = identifier; instr_ptr(ctx, step_instr)->arg2.bstr = identifier;
instr_ptr(ctx, step_instr)->arg1.uint = ctx->for_end_label; instr_ptr(ctx, step_instr)->arg1.uint = ctx->for_end_label;
...@@ -677,7 +677,7 @@ static HRESULT compile_forto_statement(compile_ctx_t *ctx, forto_statement_t *st ...@@ -677,7 +677,7 @@ static HRESULT compile_forto_statement(compile_ctx_t *ctx, forto_statement_t *st
return hres; return hres;
instr = push_instr(ctx, OP_incc); instr = push_instr(ctx, OP_incc);
if(instr == -1) if(!instr)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
instr_ptr(ctx, instr)->arg1.bstr = identifier; instr_ptr(ctx, instr)->arg1.bstr = identifier;
...@@ -920,7 +920,7 @@ static HRESULT compile_statement(compile_ctx_t *ctx, statement_t *stat) ...@@ -920,7 +920,7 @@ static HRESULT compile_statement(compile_ctx_t *ctx, statement_t *stat)
hres = compile_assign_statement(ctx, (assign_statement_t*)stat, TRUE); hres = compile_assign_statement(ctx, (assign_statement_t*)stat, TRUE);
break; break;
case STAT_STOP: case STAT_STOP:
hres = push_instr(ctx, OP_stop) == -1 ? E_OUTOFMEMORY : S_OK; hres = push_instr(ctx, OP_stop) ? S_OK : E_OUTOFMEMORY;
break; break;
case STAT_UNTIL: case STAT_UNTIL:
case STAT_WHILE: case STAT_WHILE:
...@@ -1008,7 +1008,7 @@ static HRESULT compile_func(compile_ctx_t *ctx, statement_t *stat, function_t *f ...@@ -1008,7 +1008,7 @@ static HRESULT compile_func(compile_ctx_t *ctx, statement_t *stat, function_t *f
if(ctx->prop_end_label != -1) if(ctx->prop_end_label != -1)
label_set_addr(ctx, ctx->prop_end_label); label_set_addr(ctx, ctx->prop_end_label);
if(push_instr(ctx, OP_ret) == -1) if(!push_instr(ctx, OP_ret))
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
resolve_labels(ctx, func->code_off); resolve_labels(ctx, func->code_off);
...@@ -1373,7 +1373,7 @@ static vbscode_t *alloc_vbscode(compile_ctx_t *ctx, const WCHAR *source) ...@@ -1373,7 +1373,7 @@ static vbscode_t *alloc_vbscode(compile_ctx_t *ctx, const WCHAR *source)
return NULL; return NULL;
} }
ctx->instr_cnt = 0; ctx->instr_cnt = 1;
ctx->instr_size = 32; ctx->instr_size = 32;
vbsheap_init(&ret->heap); vbsheap_init(&ret->heap);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment