[asterisk-dev] Re: [asterisk-commits] russell: trunk r48930 - in /trunk: ./ configs/ include/asterisk/ main/

Russell Bryant russell at digium.com
Sat Dec 23 20:29:54 MST 2006


Luigi Rizzo wrote:
> nice one, but what's the point of going through string fields for

thanks.  :)

> this one, given that the strings are written only once and their
> size is known at the time of allocation ?

I don't have a good reason, I guess.

> I'd rather define the struct as done other times in these cases i.e.
> 
> 	struct http_uri_redirect {
> 		struct http_uri_redirect *next;
> 		char *dest;
> 		char target[0];
> 	}
> 
> and allocate it as
> 
> 	struct http_uri_redirect *s;
> 
> 	int l1 = strlen(target) + 1;
> 	int l = sizeof(*s) + l1 + strlen(dest) + 1;
> 
> 	s = ast_calloc(l);
> 	s->dest = s->target + l1;
> 	strcpy(s->target, target);
> 	strcpy(s->dest, dest);

Good idea.  Done!

-- 
Russell Bryant
Software Engineer
Digium, Inc.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: russell.vcf
Type: text/x-vcard
Size: 266 bytes
Desc: not available
Url : http://lists.digium.com/pipermail/asterisk-dev/attachments/20061223/e4efffdd/russell.vcf


More information about the asterisk-dev mailing list