Module: sems Branch: master Commit: 252e4659e022dfbd97ebf2033467217dc0813213 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=252e4659e022dfbd97ebf2033467217dc0813213
Author: Stefan Sayer <[email protected]> Committer: Stefan Sayer <[email protected]> Date: Thu Nov 25 00:25:38 2010 +0100 fix int2str for negative numbers --- core/AmUtils.cpp | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/AmUtils.cpp b/core/AmUtils.cpp index d5842ac..0ecb188 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)); } _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
