[sr-dev] git:kamailio_3.0: core: use one buffer for int2str

Daniel-Constantin Mierla miconda at gmail.com
Tue Feb 2 13:25:17 CET 2010


Module: sip-router
Branch: kamailio_3.0
Commit: 229496c7170bcc85f517a4985f7ab4bad553c8d3
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=229496c7170bcc85f517a4985f7ab4bad553c8d3

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Tue Feb  2 13:23:03 2010 +0100

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

---

 ut.c |    3 +++
 ut.h |   13 ++++++++++---
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/ut.c b/ut.c
index 7c63941..11d4fe7 100644
--- a/ut.c
+++ b/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 */
diff --git a/ut.h b/ut.h
index 6861af7..3e4d7a6 100644
--- a/ut.h
+++ b/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)




More information about the sr-dev mailing list