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

Andrei Pelinescu-Onciul andrei at iptel.org
Tue Feb 2 14:26:56 CET 2010


On Feb 02, 2010 at 13:25, Daniel-Constantin Mierla <miconda at gmail.com> wrote:
> 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
> 
> ---
[...]

> -/* 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)

I think adding another parameter for the buffer length would be better
 (read way safer) then relying on the caller providing a large enough
 buffer.
 E.g.:
static inline char*
    int2strbuf(unsigned int l, char *r, int buf_len, int* res_len)

 and 
   if (unlikely(buf_len<INT2STR_MAX_LEN)){
   *res_len=0;
    return 0; /* => if someone missuses it => crash */
   }
 > +
>  {
> -	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];
>  }
[...]

Andrei



More information about the sr-dev mailing list