Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

class SeerData #3

Open
ygd2013520 opened this issue Jan 14, 2021 · 4 comments
Open

class SeerData #3

ygd2013520 opened this issue Jan 14, 2021 · 4 comments

Comments

@ygd2013520
Copy link

针对SeerData类的私有变量m_data[1],在setData的调用memcpy(m_data, data, size);的时候,如果数据区不为null,这个size的大小应该不止1,memcpy会不会越界,这个地方没看懂,还是说是c++的高级用法,可以指导解释一下吗?
(代码在SCHeadData.h文件里面)

@ye-ys
Copy link
Member

ye-ys commented Jan 17, 2021

不会越界,它最小16字节的报文,所有数据区都会追加到16字节报文后面。

@ye-ys
Copy link
Member

ye-ys commented Jan 17, 2021

您好,是否有工程师支持您?您可以联系我们项目经理安排专门的工程师解答您的问题。github 上的问题可能回复的不及时

@ygd2013520
Copy link
Author

我看m_header是它最小的16字节报文,这个16字节我看就是机器人命令和标识数据区大小这些,这个我看明白了的。而这个m_data就是数据区的数组,但是我看代码里面这个数组大小定义的是一个字节(uint8_t m_data[1];),如果不是最小的16字节报文,数据区的大小肯定不止1个字节吧?

@ye-ys
Copy link
Member

ye-ys commented Jan 18, 2021

uint8_t m_data[1]; memcpy(m_data,data,size); 当size超过1时不会越界。这里的m_data可以看成是一个可变数组, m_header(16字节)报文+m_data[]构成了class SeerData类的总大小

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants