Ver código fonte

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
Daniel-Constantin Mierla 15 anos atrás
pai
commit
229496c717
2 arquivos alterados com 13 adições e 3 exclusões
  1. 3 0
      ut.c
  2. 10 3
      ut.h

+ 3 - 0
ut.c

@@ -42,6 +42,9 @@
 #include "mem/mem.h"
 #include "globals.h"
 
+/* global buffer for ut.h int2str() */
+char ut_buf_int2str[INT2STR_MAX_LEN];
+
 
 /* converts a username into uid:gid,
  * returns -1 on error & 0 on success */

+ 10 - 3
ut.h

@@ -292,10 +292,10 @@ static inline char* int2str_base(unsigned int l, int* len, int base)
 
 
 
-/* returns a pointer to a static buffer containing l in asciiz & sets len */
-static inline char* int2str(unsigned int l, int* len)
+/* print int to asciiz in a string buffer
+ * - be sure result buffer is at least INT2STR_MAX_LEN in size */
+static inline char* int2strbuf(unsigned int l, char *r, int* len)
 {
-	static char r[INT2STR_MAX_LEN];
 	int i;
 	
 	i=INT2STR_MAX_LEN-2;
@@ -312,6 +312,13 @@ static inline char* int2str(unsigned int l, int* len)
 	return &r[i+1];
 }
 
+extern char ut_buf_int2str[INT2STR_MAX_LEN];
+/* returns a pointer to a static buffer containing l in asciiz & sets len */
+static inline char* int2str(unsigned long l, int* len)
+{
+	return int2strbuf(l, ut_buf_int2str, len);
+}
+
 /* Signed INTeger-TO-STRing: convers a long to a string
  * returns a pointer to a static buffer containing l in asciiz & sets len */
 static inline char* sint2str(long l, int* len)