Search code examples
candroid-source

Fatal signal 11 (SIGSEGV) in AOSP middleware


I am trying to concatenate the string like below

typedef struct IInfo
  {
    char cmAddress[6];                      
    UINT8 IpAddress[4];                     
    UINT8 hIpAddress[4];                    
  } IInfo;

In my file:

     IInfo Info;
    char CableIP[50];

   __android_log_print(ANDROID_LOG_DEBUG,"test","test--> %s:%d IpAddress[0] : %d,IpAddress[1] : %d,IpAddress[2] : %d,IpAddress[3] : %d\n", __FUNCTION__, __LINE__, Info.IpAddress[0], Info.IpAddress[1],Info.IpAddress[2], Info.IpAddress[3]);


    strcpy(CableIP,Info.IpAddress[0]);//10
    strcat(CableIP,"." );
    strcat(CableIP,Info.IpAddress[1] );//1
    strcat(CableIP,"." );
    strcat(CableIP,Info.IpAddress[2] );//120
    strcat(CableIP,"." );
    strcat(CableIP,Info.IpAddress[3] );//36
    printf("CableIP %s",CableIP);

getting print like below: test: test--> _ExecuteFUN:298 IpAddress[0] : 10,IpAddress[1] : 1,IpAddress[2] : 120,IpAddress[3] : 36

Expecting output is 10.1.120.36

but getting below error F libc : Fatal signal 11 (SIGSEGV), code 1, fault addr 0xa in tid 2888 (n0000001)

An individual array element print getting proper data, but if I do concatenation getting an error.

can you please suggest to me, where I have done wrong?


Solution

  •    char *strcpy(char *restrict dest, const char *src);
    

    The strcpy() function copies the string pointed to by src, including the terminating null byte ('\0'), to the buffer pointed to by dest. - For more

    Info.IpAddress is of type array of UINT8 rather than char*.

    I would prefer as following

    sprintf(CableIP, "%u.%u.%u.%u%c", Info.IpAddress[0], Info.IpAddress[1], Info.IpAddress[2], Info.IpAddress[3], '\0');