[Asterisk-Dev] fun with valgrind
Steve Kann
stevek at stevek.com
Tue May 10 08:44:11 MST 2005
Matthew Boehm wrote:
>I was advised to use 'valgrind' to help debug a module addon I'm making.
>
>Before I even get to that part, valgrind gave me lots of other interesting
>errors/messages with asterisk. Most of the errors are "conditional jump on
>non-initialized variable" or something of that nature.
>
>This one caught my eye:
>
>==16731==
>==16731== Source and destination overlap in strncpy(0x1BD68B26, 0x1BD68B27,
>374)
>==16731== at 0x1B904756: strncpy (mac_replace_strmem.c:113)
>==16731== by 0x1C1986B2: ??? (app_voicemail.c:5545)
>==16731== by 0x1C195D46: load_module (app_voicemail.c:5600)
>==16731== by 0x1BA2A916: __libc_start_main (in /lib/libc-2.3.2.so)
>==16731== by 0x805405C: ??? (start.S:81)
>==16731==
>==16731== Source and destination overlap in strncpy(0x1BD68B24, 0x1BD68B25,
>370)
>==16731== at 0x1B904756: strncpy (mac_replace_strmem.c:113)
>==16731== by 0x1C198675: ??? (app_voicemail.c:5549)
>==16731== by 0x1C195D46: load_module (app_voicemail.c:5600)
>==16731== by 0x1BA2A916: __libc_start_main (in /lib/libc-2.3.2.so)
>==16731== by 0x805405C: ??? (start.S:81)
>
>So I looked at the code in question. It revolves around parsing the body
>email for voicemail notifications.
>
>/* substitute strings \t and \n into the apropriate characters */
>tmpread = tmpwrite = emailbody;
>while ((tmpwrite = strchr(tmpread,'\\'))) {
> int len = strlen("\n");
> switch (tmpwrite[1]) {
> case 'n':
> strncpy(tmpwrite+len,tmpwrite+2,strlen(tmpwrite+2)+1); <=== line
>5545
> strncpy(tmpwrite,"\n",len);
> break;
> case 't':
> strncpy(tmpwrite+len,tmpwrite+2,strlen(tmpwrite+2)+1); <=== line
>5549
> strncpy(tmpwrite,"\t",len);
> break;
> default:
> ast_log(LOG_NOTICE, "Substitution routine does not support this
>character: %c\n",tmpwrite[1]);
> }
> tmpread = tmpwrite+len;
>}
>
>Could somebody explain what is going on there? It seems as if the code is
>replacing "\n" with "\n" and "\t" with "\t".
>
>
No, it looks like it's replacing the characters '\' and 'n' (two
characters), with '\n' (one character), and similar for \t..
-SteveK
More information about the asterisk-dev
mailing list