[Asterisk-Dev] [RFC] strncpy -> ast_copy_string

Jeffrey C. Ollie jeff at ocjtech.us
Mon May 2 12:50:07 MST 2005


On Mon, 2005-05-02 at 09:50 -0700, Luigi Rizzo wrote:
>
> I notice that a lot of code in asterisk uses statically sized buffers,
> which is inefficient memorywise, risky if you forget or
> misspecify the 'size' in the various stncpy, and might lead
> to unexpected behaviour because of arbitrary truncation of the strings.
> 
> I think that over time one should switch to support variable-size
> strings, and define an appropriate set of macros or functions
> to operate on them.
> Certainly deprecating strncpy in favour of a private method is
> a first step.

I think that the primary reasons for using statically allocated buffers
are:

1) Speed - You don't have the malloc/free overhead.
2) Correctness - You don't have to worry about null pointer
dereferences, double frees, etc.

Also, a lot of the string parsing in Asterisk is processing protocol
headers and data.  Many protocols define upper limits on the sizes of
various fields so you don't really need to worry about handling very
large strings.

Jeff

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.digium.com/pipermail/asterisk-dev/attachments/20050502/98df70ee/attachment.pgp


More information about the asterisk-dev mailing list