【发布时间】:2014-01-10 01:40:58
【问题描述】:
iOS 中的 memcpy 有什么替代品吗? 据我所知,memcpy 并不“安全”,建议的替代方案是“memcpy_s”
但是,将 memcpy 替换为 memcpy_s 后,由于“架构 armv7 的未定义符号:”问题,代码无法编译。
我该如何解决这个问题?如何设置项目设置?任何帮助将不胜感激。
来自 AsyncSocket.m 的一些代码:
- (CFIndex)readIntoBuffer:(UInt8 *)buffer maxLength:(CFIndex)length
{
if([_partialReadBuffer length] > 0)
{
// Determine the maximum amount of data to read
CFIndex bytesToRead = MIN(length, [_partialReadBuffer length]);
// Copy the bytes from the buffer
memcpy(buffer, [_partialReadBuffer bytes], bytesToRead);
// Remove the copied bytes from the buffer
[_partialReadBuffer replaceBytesInRange:NSMakeRange(0, bytesToRead) withBytes:NULL length:0];
return bytesToRead;
}
else
{
return CFReadStreamRead(_theReadStream, buffer, length);
}
}
【问题讨论】:
-
请在您使用 memcpy 的地方发布一些代码。
-
在这里显示一些代码...
-
您可以尝试使用
strcpy()。 -
@user3007735:
strcopy()复制一个以 NUL 结尾的字符串,并且不能替换复制给定字节数的memcpy。 -
我想知道 __builtin___memcpy_chk 是否是安全的。
标签: ios objective-c memcpy