Commit 70cd4153 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

vbscript: Alloc vbscode_t before parsing the script.

parent d12de646
...@@ -1851,16 +1851,24 @@ void release_vbscode(vbscode_t *code) ...@@ -1851,16 +1851,24 @@ void release_vbscode(vbscode_t *code)
static vbscode_t *alloc_vbscode(compile_ctx_t *ctx, const WCHAR *source) static vbscode_t *alloc_vbscode(compile_ctx_t *ctx, const WCHAR *source)
{ {
vbscode_t *ret; vbscode_t *ret;
size_t len;
len = source ? lstrlenW(source) : 0;
if(len > INT32_MAX)
return NULL;
ret = heap_alloc_zero(sizeof(*ret)); ret = heap_alloc_zero(sizeof(*ret));
if(!ret) if(!ret)
return NULL; return NULL;
ret->source = heap_strdupW(source); ret->source = heap_alloc((len + 1) * sizeof(WCHAR));
if(!ret->source) { if(!ret->source) {
heap_free(ret); heap_free(ret);
return NULL; return NULL;
} }
if(len)
memcpy(ret->source, source, len * sizeof(WCHAR));
ret->source[len] = 0;
ret->instrs = heap_alloc(32*sizeof(instr_t)); ret->instrs = heap_alloc(32*sizeof(instr_t));
if(!ret->instrs) { if(!ret->instrs) {
...@@ -1872,8 +1880,6 @@ static vbscode_t *alloc_vbscode(compile_ctx_t *ctx, const WCHAR *source) ...@@ -1872,8 +1880,6 @@ static vbscode_t *alloc_vbscode(compile_ctx_t *ctx, const WCHAR *source)
ctx->instr_size = 32; ctx->instr_size = 32;
heap_pool_init(&ret->heap); heap_pool_init(&ret->heap);
ret->option_explicit = ctx->parser.option_explicit;
ret->main_code.type = FUNC_GLOBAL; ret->main_code.type = FUNC_GLOBAL;
ret->main_code.code_ctx = ret; ret->main_code.code_ctx = ret;
ret->ref = 1; ret->ref = 1;
...@@ -1899,15 +1905,16 @@ HRESULT compile_script(script_ctx_t *script, const WCHAR *src, const WCHAR *deli ...@@ -1899,15 +1905,16 @@ HRESULT compile_script(script_ctx_t *script, const WCHAR *src, const WCHAR *deli
vbscode_t *code; vbscode_t *code;
HRESULT hres; HRESULT hres;
if (!src) src = L"";
hres = parse_script(&ctx.parser, src, delimiter, flags);
if(FAILED(hres))
return compile_error(script, hres);
code = ctx.code = alloc_vbscode(&ctx, src); code = ctx.code = alloc_vbscode(&ctx, src);
if(!ctx.code) if(!ctx.code)
return compile_error(script, E_OUTOFMEMORY); return E_OUTOFMEMORY;
hres = parse_script(&ctx.parser, code->source, delimiter, flags);
if(FAILED(hres)) {
hres = compile_error(script, hres);
release_vbscode(code);
return hres;
}
ctx.func_decls = NULL; ctx.func_decls = NULL;
ctx.labels = NULL; ctx.labels = NULL;
...@@ -1922,6 +1929,8 @@ HRESULT compile_script(script_ctx_t *script, const WCHAR *src, const WCHAR *deli ...@@ -1922,6 +1929,8 @@ HRESULT compile_script(script_ctx_t *script, const WCHAR *src, const WCHAR *deli
} }
ctx.global_consts = ctx.const_decls; ctx.global_consts = ctx.const_decls;
code->option_explicit = ctx.parser.option_explicit;
for(func_decl = ctx.func_decls; func_decl; func_decl = func_decl->next) { for(func_decl = ctx.func_decls; func_decl; func_decl = func_decl->next) {
hres = create_function(&ctx, func_decl, &new_func); hres = create_function(&ctx, func_decl, &new_func);
......
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