我正在尝试将uint8_t *复制到char数组中,uint8_t *不终止,但是我还有另一个uint8_t,其消息长度。 我如何将uint8_t *复制到char数组中而又不会得到segfauts。
uint8_t *name; //Set to something beforehand, it's part of an server STUN.
uint8 name_length; //Also set to something I just know is less than 255.
//I've tried
char nameArray[255];
memcpy(nameArray, name, name_length-1);
nameArray[name_length] = '\0';
由于读取大小无效而导致段错误
答案 0 :(得分:1)
由于变量x_link = [125, 257, None, 125, 787, None]
y_link = [383, 588, None, 383, 212, None]
z_link = [65, 85, None, 65, 526, None]
link_size = [3,6]
trace1= go.Scatter3d(
x = x_link[:3],
y = y_link[:3],
z = z_link[:3],
line=dict(
color='green',
width=link_size[0]
)
)
trace2= go.Scatter3d(
x = x_link[3:],
y = y_link[3:],
z = z_link[3:],
line=dict(
color='red',
width=link_size[1]
)
)
fig = go.Figure(data=[trace1, trace2])
在调用name_length
处的整数提升,被转换为memcpy()
。如果值为0(零),则减1将得出值-1。然后将其转换为int
,得到SIZE_MAX。 size_t
很高兴开始复制该金额,但超出了允许的地址范围的限制。
由于首先减去1是错误的,所以将其删除。