Random exclamation point at end of strings
Hey,
I did a Google search prior to registering and posting this question, and I found a post on this board with a similar problem. After following the advice in that thead, I still found myself facing the same problem.
I am writing a program that scans a directory of source code files and determines if there are any missing dependencies. The strange problem I am encountering, however, is that at a certain part of my program, an exclamation point is appended to some of the strings. This causes a problem later on, as the program determines that there is not an exact match and that the malformed string is a missing dependency.
After using numerous debug statements, I have narrowed the occurence of the problem to the following segment of code (I will include the whole function):
Code:
HashEntry *create_hash_entry(void *val)
{
HashEntry *he;
//This is the problematic segment:
printf("debug: val(before): %s\n", val);
if((he = malloc(sizeof(HashEntry))) == NULL)
{
fprintf(stderr, "error: could not allocate space for HashEntry 'he'; function: create_hash_entry()\n");
abort();
}
printf("debug: val(after): %s\n", val);
//End the problematic segment
he->key = hash(val);
he->value = val;
he->next = NULL;
return he;
}
Here are the first few lines of the output:
Code:
debug: val(before): cde_transaction_change.h
debug: val(after): cde_transaction_change.h!
debug: val(before): cde_transaction_delete.h
debug: val(after): cde_transaction_delete.h!
debug: val(before): fl_tpl_retro_summ_recs.h
debug: val(after): fl_tpl_retro_summ_recs.h!
...and etcetera. The strange thing is that the ONLY strings which have an exclamation mark appended to them are exactly 24 characters long, with the ! making the 25th character(at val[24]).
I have no idea why this particular malloc() call seems to add the exclamation mark. Perhaps somone has encountered and conquered this problem before? I will continue to work on this, but any help is VERY MUCH appreciated!
Thanks!