Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
问题描述
在32位系统上, 读写文件过程,seek 调用跟期望的不一致, 文件没有被正确读写,导致测试用例失败。
通过在代码里加打印,发现主要是在seek 函数打印传入的数据异常。如下图所示:
本来传入的是-4120, 但是打印的结果是4294963176.
于是,判断是类型转换导致的。
调试记录
经过调试,发现下面两个函数类型的差异:
被调函数定义是seek(size_t len)
调用处代码传的是int64_t
整个过程的发生了int64_t --> size_t --> off_t 的转换。
我们在代码里打印int64_t, size_t, off_t的大小
编译之后,发现int64_t 是8字节, size_t 是4字节的, off_t 又是8字节的,这会导致很严重的问题。
结论
由上面可知,是avro本身的代码在调用过程中类型不一致导致的。发生了 int64_t(64) --> size_t(32) --> off_t(64) 的转换。这就导致了数据被截断了。
当传入为负数时, 32位的size_t转化成64位的off_t 数据出错。
因此,我们将相关函数的size_t 改成int64_t,这样可以解决我所遇到的bug。但是在整个代码里,还有许多地方涉及到这种类似变换,我们暂未修改。