Browse code

core: use one buffer for int2str

- static declaration inside ut.h function results in hard copy to many
places, affecting acc detection of int to str conversions in buffer
- reported by Alex Balashov
(cherry picked from commit 229496c7170bcc85f517a4985f7ab4bad553c8d3)

Daniel-Constantin Mierla authored on 02/02/2010 12:23:03
Showing 2 changed files
... ...
@@ -42,6 +42,9 @@
42 42
 #include "mem/mem.h"
43 43
 #include "globals.h"
44 44
 
45
+/* global buffer for ut.h int2str() */
46
+char ut_buf_int2str[INT2STR_MAX_LEN];
47
+
45 48
 
46 49
 /* converts a username into uid:gid,
47 50
  * returns -1 on error & 0 on success */
... ...
@@ -292,10 +292,10 @@ static inline char* int2str_base(unsigned int l, int* len, int base)
292 292
 
293 293
 
294 294
 
295
-/* returns a pointer to a static buffer containing l in asciiz & sets len */
296
-static inline char* int2str(unsigned int l, int* len)
295
+/* print int to asciiz in a string buffer
296
+ * - be sure result buffer is at least INT2STR_MAX_LEN in size */
297
+static inline char* int2strbuf(unsigned int l, char *r, int* len)
297 298
 {
298
-	static char r[INT2STR_MAX_LEN];
299 299
 	int i;
300 300
 	
301 301
 	i=INT2STR_MAX_LEN-2;
... ...
@@ -312,6 +312,13 @@ static inline char* int2str(unsigned int l, int* len)
312 312
 	return &r[i+1];
313 313
 }
314 314
 
315
+extern char ut_buf_int2str[INT2STR_MAX_LEN];
316
+/* returns a pointer to a static buffer containing l in asciiz & sets len */
317
+static inline char* int2str(unsigned long l, int* len)
318
+{
319
+	return int2strbuf(l, ut_buf_int2str, len);
320
+}
321
+
315 322
 /* Signed INTeger-TO-STRing: convers a long to a string
316 323
  * returns a pointer to a static buffer containing l in asciiz & sets len */
317 324
 static inline char* sint2str(long l, int* len)