@@ -175,41 +175,32 @@ static inline void fbuffer_append_char(FBuffer *fb, char newchr)
175
175
fb->len ++;
176
176
}
177
177
178
- static inline long fultoa (unsigned long number, char *buf)
179
- {
180
- static const char digits[] = " 0123456789" ;
181
- char * tmp = buf;
182
-
183
- do *tmp-- = digits[number % 10 ]; while (number /= 10 );
184
- return buf - tmp;
185
- }
186
-
187
- #define MAX_CHARS_FOR_LONG 20
188
-
189
178
/*
190
179
* Appends the decimal string representation of \a number into the buffer.
191
180
*/
192
181
static void fbuffer_append_long (FBuffer *fb, long number)
193
182
{
194
183
/*
195
- * The to_text_from_ulong implementation produces digits left-to-right,
196
- * allowing us to write directly into the buffer. However, we don't know
197
- * how many characters we'll need exactly .
184
+ * The to_text_from_ulong() function produces digits left-to-right,
185
+ * allowing us to write directly into the buffer, but we don't know
186
+ * the number of resulting characters .
198
187
*
199
- * However, the number argument is always in the range 0xc000000000000000
200
- * to 0x3fffffffffffffff, or, in decimal, -4611686018427387904 to
201
- * 4611686018427387903. We therefore need at most 20 chars in the target
202
- * buffer .
188
+ * We do know, however, that the ` number` argument is always in the
189
+ * range 0xc000000000000000 to 0x3fffffffffffffff, or, in decimal,
190
+ * -4611686018427387904 to 4611686018427387903. The max number of chars
191
+ * generated is therefore 20 (including a potential sign character) .
203
192
*/
204
193
194
+ static const int MAX_CHARS_FOR_LONG = 20 ;
195
+
205
196
fbuffer_inc_capa (fb, MAX_CHARS_FOR_LONG);
206
197
207
198
if (number < 0 ) {
208
199
fbuffer_append_reserved_char (fb, ' -' );
209
200
210
201
/*
211
- * Since LONG_MIN is not in the valid range , `number = -number` always turns
212
- * a negative number into the positive.
202
+ * Since number is always > LONG_MIN , `-number` will not overflow
203
+ * and is always the positive abs() value .
213
204
*/
214
205
number = -number;
215
206
}
0 commit comments