summaryrefslogtreecommitdiff
path: root/ext/standard/php_smart_str.h
diff options
context:
space:
mode:
authorStanislav Malyshev <stas@php.net>2001-08-20 15:26:10 +0000
committerStanislav Malyshev <stas@php.net>2001-08-20 15:26:10 +0000
commit902100a6920dd49c681d90b41f0a9507389cab65 (patch)
tree11cd160ed57429fd7b4c3bcba5773ddee4378588 /ext/standard/php_smart_str.h
parent9b3df86e8db76a9652cf39bc5bcb35e9f8d1f1d4 (diff)
downloadphp-git-902100a6920dd49c681d90b41f0a9507389cab65.tar.gz
Fix long printing in smart_str_print_long
Diffstat (limited to 'ext/standard/php_smart_str.h')
-rw-r--r--ext/standard/php_smart_str.h23
1 files changed, 14 insertions, 9 deletions
diff --git a/ext/standard/php_smart_str.h b/ext/standard/php_smart_str.h
index 167fc1b643..0edaa4a9d4 100644
--- a/ext/standard/php_smart_str.h
+++ b/ext/standard/php_smart_str.h
@@ -78,27 +78,32 @@ static inline void smart_str_appendl_ex(smart_str *dest, const char *src, size_t
static inline char *smart_str_print_long(char *buf, long num)
{
+ /* TBFixed: think how to do it one-pass */
+ long tmp;
char *p = buf;
- long tmp = 0;
int n = 0;
+
+ if(num == 0) {
+ *p++ = '0';
+ return p;
+ }
if (num < 0) {
num = -num;
*p++ = '-';
}
+ for (tmp = num; tmp > 0; n++) {
+ tmp /= 10;
+ }
+ p += n;
+
while (num > 0) {
- tmp = tmp * 10 + (num % 10);
+ *(--p) = (num % 10) + '0';
num /= 10;
- n++;
}
- do {
- *p++ = (tmp % 10) + '0';
- tmp /= 10;
- } while (--n > 0);
-
- return p;
+ return p+n;
}
static inline void smart_str_append_long_ex(smart_str *dest, long num, int type)