memset causing coredump

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,
please make sure, that msisdn points on allocated memory by malloc before using memset.
what is msisdn?

It should be an allocated char* array (or interpreted as such).
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
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.
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.