C - memset segfault for statically allocated char array

Posted by user1327031 on Stack Overflow See other posts from Stack Overflow or by user1327031
Published on 2012-04-11T16:48:00Z Indexed on 2012/04/11 17:29 UTC
Read the original article Hit count: 175

Filed under:
|
|

I get a segfault when trying to memset an array of chars that was allocated statically, but not for an array of the same length that was allocated using malloc.

variable definitions:

    //static
    char inBuff[IN_BUFF_LEN];
    //dynamic
    char * inBuffD;

function call:

    //static, cast used because char** != char (*) [n]
    serverInit(portNum, (char**) &inBuff, &serv_addr, &sockfd)
    //dynamic
    serverInit(portNum, &inBuffD, &serv_addr, &sockfd)

use within the function:

    memset(*inBuffAdr, 0, IN_BUFF_LEN);

I suspect that my problem is in the difference of the function calls, or to be more precise, my incomplete understanding of the "char** != char (*) [n]" situation. But I have been banging at this for too long and can't see the forest from the trees so any hints and advice would be very appreciated.

© Stack Overflow or respective owner

Related posts about c

    Related posts about segmentation-fault