memset causing coredump

Jan 13, 2010 at 11:36am
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
please make sure, that msisdn points on allocated memory by malloc before using memset.
Jan 13, 2010 at 3:22pm
what is msisdn?

It should be an allocated char* array (or interpreted as such).
Jan 13, 2010 at 4:59pm
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
Jan 14, 2010 at 4:45am
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
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.
Topic archived. No new replies allowed.