I'm while using below function during my C code for hooking up towards the oracle database. The below function is leading to segmentation fault sometime while work on another time

static int Connect(char *string)
{
EXEC SQL BEGIN DECLARE SECTION;
    static char login[80];
EXEC SQL END DECLARE SECTION;

    strcpy((char *)login, string);

    EXEC SQL CONNECT :login ;

    if (sqlca.sqlcode < 0) 
        return(-1);
    return(0);
}

Below may be the debugger report produced using the core file. Any suggestions about this.

program terminated by signal SEGV (no mapping at the fault address)
0xffffffffffffffff:     <bad address 0xffffffffffffffff>
Current function is Connect
    375    sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn);

  [20] 0xffffffff7e587078(0x0, 0x100210f80, 0xffffffff7fffc850, 0x1000e4dd0, 0xff000000000000, 0x8080808080808080), at 0xffffffff7e587078
=>[21] login(orastring = 0xffffffff7fffcef8 "user123/abcd@sunn.adams"), line 375 in "connect.c"

In the debugger report, seg fault is due to being able to access inaccessible memory.

I recommend two places to place some inspections. (a) Check input parameter 'string' for NULL values before utilizing it. (b) Use strncpy() rather than strcpy()