diff --git a/core/AmUtils.cpp b/core/AmUtils.cpp index d5842ac6..0ecb1881 100644 --- a/core/AmUtils.cpp +++ b/core/AmUtils.cpp @@ -70,16 +70,21 @@ static char _int2str_lookup[] = { '0', '1', '2', '3', '4', '5', '6' , '7', '8', string int2str(int val) { - char buffer[64] = {0}; + char buffer[64] = {0,0}; int i=62; div_t d; - d.quot = val; + d.quot = abs(val); do{ d = div(d.quot,10); buffer[i] = _int2str_lookup[d.rem]; }while(--i && d.quot); + if (i && (val<0)) { + buffer[i]='-'; + i--; + } + return string((char*)(buffer+i+1)); }