Jan 13, 2010 at 11:36am UTC
I have a below line of code which i think the source of coredump
memset(msisdn,'\0',10);
can anybody please explain on which instances memset causes core?
Thx in advance,
Jan 13, 2010 at 1:01pm UTC
please make sure, that msisdn points on allocated memory by malloc before using memset.
Jan 13, 2010 at 3:22pm UTC
what is msisdn?
It should be an allocated char* array (or interpreted as such).
Jan 13, 2010 at 4:59pm UTC
Two possible scenarios come to mind:
1. msisdn is not pointing to your dynamically allocated memory
2. memset is writing beyond the size of what has been allocated
Last edited on Jan 13, 2010 at 4:59pm UTC
Jan 14, 2010 at 4:45am UTC
Thanx all for a very useful response. I forgot to mention that msisdn is character array,
the code is exactly as below.
char msisdn[10];
memset(msisdn,'\0',10);
the value to be stored in msisdn is of 8 digits only.
Jan 14, 2010 at 5:45am UTC
A program should not crash by calling memset() like that on such an array. If it's crashing, there must memory corruption caused by a bug elsewhere in the program.