From 5e768c8765bc70d70599dd9a6e5d27875de490e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn-Egil=20Dahlberg?= Date: Thu, 11 Jul 2013 18:39:04 +0200 Subject: Fix erlang:system_info(compile_info) Allocation needs to be in correct order. --- erts/emulator/beam/erl_bif_info.c | 41 ++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'erts/emulator/beam/erl_bif_info.c') diff --git a/erts/emulator/beam/erl_bif_info.c b/erts/emulator/beam/erl_bif_info.c index a43eee6420..673dfc658c 100755 --- a/erts/emulator/beam/erl_bif_info.c +++ b/erts/emulator/beam/erl_bif_info.c @@ -2612,24 +2612,29 @@ BIF_RETTYPE system_info_1(BIF_ALIST_1) } #endif else if (ERTS_IS_ATOM_STR("compile_info",BIF_ARG_1)) { - Eterm *hp = HAlloc(BIF_P, 3*3+3*2); /* three two tuples + - three list elems */ - Eterm res = NIL; - Eterm *lhp = HAlloc(BIF_P, 2*(strlen(erts_build_flags_CONFIG_H)+ - strlen(erts_build_flags_CFLAGS)+ - strlen(erts_build_flags_LDFLAGS))); - - res = CONS(hp+9,TUPLE2(hp, am_config_h, - buf_to_intlist(&lhp, erts_build_flags_CONFIG_H, - strlen(erts_build_flags_CONFIG_H), NIL)),res); - res = CONS(hp+11,TUPLE2(hp+3, am_cflags, - buf_to_intlist(&lhp, erts_build_flags_CFLAGS, - strlen(erts_build_flags_CFLAGS), NIL)),res); - res = CONS(hp+13,TUPLE2(hp+6, am_ldflags, - buf_to_intlist(&lhp, erts_build_flags_LDFLAGS, - strlen(erts_build_flags_LDFLAGS), NIL)),res); - - BIF_RET(res); + Uint sz; + Eterm res = NIL, tup, text; + Eterm *hp = HAlloc(BIF_P, 3*(2 + 3) + /* three 2-tuples and three cons */ + 2*(strlen(erts_build_flags_CONFIG_H) + + strlen(erts_build_flags_CFLAGS) + + strlen(erts_build_flags_LDFLAGS))); + + sz = strlen(erts_build_flags_CONFIG_H); + text = buf_to_intlist(&hp, erts_build_flags_CONFIG_H, sz, NIL); + tup = TUPLE2(hp, am_config_h, text); hp += 3; + res = CONS(hp, tup, res); hp += 2; + + sz = strlen(erts_build_flags_CFLAGS); + text = buf_to_intlist(&hp, erts_build_flags_CFLAGS, sz, NIL); + tup = TUPLE2(hp, am_cflags, text); hp += 3; + res = CONS(hp, tup, res); hp += 2; + + sz = strlen(erts_build_flags_LDFLAGS); + text = buf_to_intlist(&hp, erts_build_flags_LDFLAGS, sz, NIL); + tup = TUPLE2(hp, am_ldflags, text); hp += 3; + res = CONS(hp, tup, res); hp += 2; + + BIF_RET(res); } BIF_ERROR(BIF_P, BADARG); -- cgit v1.2.3