Closed aleshaleksey closed 4 years ago
You've stumbled upon a bug, which apparently is not caught by our tests :---)
It shouldn't be 24, it should be 3. Sharp edges and all. Unfortunately I don't have to to fix it for a couple of weeks, but I'll get to designing a test for it, and fix the program.
Thanks!
Thanks for the report! I've added (mostly flipped the switch) libsegyio support for int24, and fixed the bswap bug you found.
This is not so much a problem as a "Hmm, that's funny. Maybe I'll learn something if I ask a question" kind of issue.
So there are a bunch of functions:
bswap64vec
,bswap32vec
,bswap24vec
andbswap16vec
. in "lib/src/segy.c" (approximately lines 1778), which is fine. I was looking at them and noticed thatbswap24vec
was a little bit (no pun intended) odd. Obviously in "normal" computing 24-bit (3-byte) numerical types are something of a unicorn, so that explains why thebswap24vec
function is different from the rest of thebswap
functions (aka 24-bit (3-byte) numerical types are not particularly "standard").However, here we have the use of
sizeof(int_whatever_t)
which returns the number of bytes forint_whatever_t
in most of the functions, (which would be 2, 4 and 8 forint16_t
,int32_t
andint64_t
respectively according to C Playground), but a straight up "24" is used inbswap24vec
which is the bit count and not the byte count.So in
( char* xs = begin; xs != end; xs += sizeof(int32_t)
I believe the pointer is being incremented by 4 bytes each time, while in(char* xs = begin; xs != end; xs += 24)
it is being incremented by 24? Is this Ok? Doesbswap24vec
end up skipping a bunch of bytes? If not, would someone be able to point me to what I am misunderstanding (yes, everything, of course, but...).Again, I would like to apologise for wasting your time if I am misunderstanding the nature of the code here.