Skip to content

Commit 902100a

Browse files
committed
Fix long printing in smart_str_print_long
1 parent 9b3df86 commit 902100a

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

ext/standard/php_smart_str.h

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,27 +78,32 @@ static inline void smart_str_appendl_ex(smart_str *dest, const char *src, size_t
7878

7979
static inline char *smart_str_print_long(char *buf, long num)
8080
{
81+
/* TBFixed: think how to do it one-pass */
82+
long tmp;
8183
char *p = buf;
82-
long tmp = 0;
8384
int n = 0;
85+
86+
if(num == 0) {
87+
*p++ = '0';
88+
return p;
89+
}
8490

8591
if (num < 0) {
8692
num = -num;
8793
*p++ = '-';
8894
}
8995

96+
for (tmp = num; tmp > 0; n++) {
97+
tmp /= 10;
98+
}
99+
p += n;
100+
90101
while (num > 0) {
91-
tmp = tmp * 10 + (num % 10);
102+
*(--p) = (num % 10) + '0';
92103
num /= 10;
93-
n++;
94104
}
95105

96-
do {
97-
*p++ = (tmp % 10) + '0';
98-
tmp /= 10;
99-
} while (--n > 0);
100-
101-
return p;
106+
return p+n;
102107
}
103108

104109
static inline void smart_str_append_long_ex(smart_str *dest, long num, int type)

0 commit comments

Comments
 (0)