Suspicious pointer-to-pointer conversion (area too small)

£可爱£侵袭症+ 提交于 2020-01-06 12:41:33

问题


I am getting this warning for my logic -

Logic :

uint8_t     *m_data;

uint32_t* datap = (uint32_t*)m_data;

Warning:

Info 826: Suspicious pointer-to-pointer conversion (area too small)

As it is required to typecast the value during assignment ..And i am not feeling there is something wrong in given line of code ..how I can suppress this warning or remove it from build


回答1:


That's not a correct cast, you're attempting to interpret a pointer to a byte as a pointer to 4 bytes, and can lead to unexpected results. If uint32_t has different alignment requirements than uint8_t, you might even get a different value of the pointer, and also what it points to. If you want to convert the value, just do:

uint32_t datap;
datap = static_cast<uint32_t>(*m_data);


来源:https://stackoverflow.com/questions/21552209/suspicious-pointer-to-pointer-conversion-area-too-small

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!