LLVM GCC 4.2 EXC_BAD_ACCESS
下面的代码在 GCC 4.2 上运行得很好,但在 LLVM GCC 4.2 中因 EXC_BAD_ACCESS 而失败
- (double_t)readDouble {
double_t *dt = (double_t *)(buffer+offset);
double_t ret = *dt; // Program received signal: EXC_BAD_ACCESS
offset += 8;
return ret;
}
这就是我分配
int dataLength = [data length];
buffer = malloc(dataLength + 1);
buffer[dataLength] = 0; // null terminate to log
[data getBytes:(void *)buffer length:[data length]];
//NSLog(@"%s", buffer);
偏移量和缓冲区的方式,就像
@interface PRDataSet : NSObject {
NSMutableArray *tables;
NSMutableDictionary *tablesByName;
NSMutableDictionary *tablesById;
@private
NSURLConnection *conn;
int offset;
char *buffer;
}
是偏移量在范围内。 在使用缓冲区之前我不会释放它。
有什么想法吗?
Below code runs just fine on GCC 4.2 but fails with EXC_BAD_ACCESS in LLVM GCC 4.2
- (double_t)readDouble {
double_t *dt = (double_t *)(buffer+offset);
double_t ret = *dt; // Program received signal: EXC_BAD_ACCESS
offset += 8;
return ret;
}
That's how I allocate
int dataLength = [data length];
buffer = malloc(dataLength + 1);
buffer[dataLength] = 0; // null terminate to log
[data getBytes:(void *)buffer length:[data length]];
//NSLog(@"%s", buffer);
Offset and buffer is like
@interface PRDataSet : NSObject {
NSMutableArray *tables;
NSMutableDictionary *tablesByName;
NSMutableDictionary *tablesById;
@private
NSURLConnection *conn;
int offset;
char *buffer;
}
Yes offset is within range.
I do not free the buffer before I use it.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能是对齐问题。 ARM 处理器(以及许多其他处理器)对数据对齐有限制,例如,它们只能从 4 或 8 的倍数地址读取和写入浮点数。
从代码中分配缓冲区的方式来看,它可能未正确分配,或者您的
double_t
数据元素未在缓冲区内对齐。为了避免这个问题,您应该尝试首先将数据复制到对齐的缓冲区中,然后从那里读取数据。
This could be an aligment problem. The ARM processors (and many other processors) have restrictions regarding the data alignment, e.g. they can only read and write floating-point numbers from addresses that are a multiple of 4 or 8.
From the way the buffer is allocated in your code, it might not be allocated properly, or your
double_t
data elements aren't aligned within the buffer.In order to avoid the problem, you should try to first copy the data into an aligned buffer and read it from there.
LLVM 只是不直接读取浮点数。
这是解决方案:
LLVM just doesn't read float directly.
Here's the solution: