From 386050e35675d3e4336f48a19b8562f9a62c1624 Mon Sep 17 00:00:00 2001 From: Steve Vinoski Date: Wed, 6 Oct 2010 11:28:08 -0400 Subject: teach ei_x_format to handle unary - and + Teach the format string parser used for ei_x_format() and ei_x_format_wo_ver() about unary negative and positive operators on numbers. Previously, passing a negative numeric constant or a positive numeric constant with an explicit leading plus sign within the format string would cause these functions to fail. Augment the format_wo_ver unit test in the ei_format suite with a regression test for these cases. An easy way to reproduce the problem is to use erl_call: erl_call -s foo@bar -a 'erlang list_to_integer [-1]' Without this change, erl_call fails with a -1 exit status. With this change, it properly prints "-1". --- lib/erl_interface/src/misc/ei_format.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/erl_interface/src/misc') diff --git a/lib/erl_interface/src/misc/ei_format.c b/lib/erl_interface/src/misc/ei_format.c index 08235d0ebe..b35421d4b2 100644 --- a/lib/erl_interface/src/misc/ei_format.c +++ b/lib/erl_interface/src/misc/ei_format.c @@ -106,6 +106,8 @@ static int eiformat(const char** fmt, union arg** args, ei_x_buff* x) default: if (isdigit((int)*p)) res = pdigit(&p, x); + else if ((*p == '-' || *p == '+') && isdigit((int)*(p+1))) + res = pdigit(&p, x); else if (islower((int)*p)) res = patom(&p, x); else @@ -149,6 +151,8 @@ static int pdigit(const char** fmt, ei_x_buff* x) double d; long l; + if (**fmt == '-' || **fmt == '+') + (*fmt)++; for (;;) { c = *(*fmt)++; if (isdigit((int)c)) -- cgit v1.2.3