[asterisk-dev] reasoning behind char[0]
Boehm, Matthew
mboehm at theplanet.com
Wed Sep 30 09:40:39 CDT 2009
Hello gents,
I've been trying to understand some of the concepts in linkedlist.h and
loader.c. My first quandry revolves around the use of "char
resource[0]" in loader.c, struct ast_module.
In writing my own code examples to understand, I found this along with
ast_module -> entry -> next to be most troublesome. Nowhere in the code,
do I find were ->next is set to null, thus preventing AST_LIST_TRAVERSE
from accessing random memory space. In my code, I always segFaulted on
the first iteration over the list (containing 1 entry) because the for
loop tried to access a ->next that didn't exist because it wasn't set to
NULL.
So I change the behavior of AST_LIST_INSERT_TAIL to, upon !head->first
to set the .next = NULL. While this worked, this caused a strange
behavior in the value of resource[0] being truncated or just not set
correctly.
So I was stuck. Not setting .next to NULL allowed resource[] to maintain
its values but seg'd on any traversing of the list. Setting .next to
NULL allowed for traversing of the list but put garbled data into the
values of resource[].
My only fix was to change resource[0] to char *resource and do an
ast_calloc on strlen(resource_in) right before the strcpy in
load_dynamic_module().
I am now able to have .next = NULL which keeps my traversals sane and
preserves my values of "resource".
Comments?
-Matthew
Matthew Boehm,
Senior MySQL DBA, The Planet
E: mboehm at theplanet.com
C: 832-253-8258
O: 281-714-4018
Certified MySQL 5.0 DBA, #226735534
Certified MySQL Cluster 5.1 DBA, #227094842
RedHat Certified Engineer, #805009324738628
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-dev/attachments/20090930/8754e8d8/attachment.htm
More information about the asterisk-dev
mailing list