开发者

warning: pointer targets in passing argument 1 of '__builtin___strncpy_chk' differ in signedness

开发者 https://www.devze.com 2023-03-14 00:28 出处:网络
I am getting a warning for the below code. //someother class #define EVENT_ID_DESCRIPTION_LEN64 struct FILE_DESCRIPTIONS

I am getting a warning for the below code.

//someother class 
#define EVENT_ID_DESCRIPTION_LEN  64
struct FILE_DESCRIPTIONS
{
    uint32_t  uFileID;
    uint32_t  uDescriptionLen; 
    int8_t   szDescription[FILE_ID_DESCRIPTION_LEN];
};

//defined inside a function of someother class
int8_t  chTemp[EVENT_ID_DESCRIPTION_LEN + 1];
strncpy(chTemp,pMsg->st.aDescriptions[nIndex].szDescription,EVENT_ID_DESCRIPTION_LEN);

warning: pointer targets in passing argument 1 of '_builtin__strncpy_chk' differ in signedness

The value from which i'm storing from is also uint8_开发者_开发知识库t and that gets stored onto is also uint8_t.what might be the cause of this warning. Thanks in advance.


Actually, your code is defining int8_t (signed int) and not uint8_t (unsigned int) as you think. Did you spotted it?

You have to change your variable to:

uint8_t  chTemp[EVENT_ID_DESCRIPTION_LEN + 1];


Remember that in C, the three types char, unsigned char and signed char are all distinct, and strncpy expects a char. If your int8_t is defined as signed char, you have conflicting types. Best to use an actual char, non?


Can't you use memcpy instead?

memcpy(chTemp, pMsg->st.aDescriptions[nIndex].szDescription, EVENT_ID_DESCRIPTION_LEN);
0

精彩评论

暂无评论...
验证码 换一张
取 消