Make the VQA seek command's origin explicit - #114
Conversation
Krisztiaan
left a comment
There was a problem hiding this comment.
Nice, just an extra step suggested
06105c0 to
3f82637
Compare
| */ | ||
| inline int VQA_DecodeSeekOrigin(void *buffer) | ||
| { | ||
| return (int)(std::intptr_t)buffer; |
There was a problem hiding this comment.
What is the purpose of this cascade cast if you can make a specific reinterpret_cast<int>(buffer);?
There was a problem hiding this comment.
That won't compile on a 64-bit target. It only compiles on win32 because a pointer there is 32 bits.
So it would become static_cast<int>(reinterpret_cast<std::intptr_t>(buffer)) if we want to avoid C-style casts...
There was a problem hiding this comment.
So it would become
static_cast<int>(reinterpret_cast<std::intptr_t>(buffer))if we want to avoid C-style casts...
Em, no, 1 specific c++ cast static_cast<int>(buffer) is enough.
There was a problem hiding this comment.
The problem here is that on x64 this will become a warning, likely https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4311?view=msvc-170
| /* VQACMD_SEEK and VQACMD_SEEKPEEK carry the seek origin in Buffer rather | ||
| * than a pointer. It comes back at pointer width before narrowing to the | ||
| * int origin that lseek and FileClass::Seek take. | ||
| */ | ||
| inline int VQA_DecodeSeekOrigin(void *buffer) |
There was a problem hiding this comment.
What is the purpose of this function if its code just return the void pointer as int (even not int32_t)
There was a problem hiding this comment.
It returns int because that's the origin parameter of lseek and FileClass::Seek. int32_t is a typedef for int on both MSVC and clang, so that would change the spelling and nothing else, while no longer matching the API it feeds.
The smell is real though: the protocol hands you an integer in a pointer parameter, and a decoder is the best we can do without changing the protocol.
3f82637 to
076fb5b
Compare
VQACMD_SEEKcarries lseek's origin in its buffer argument, but the comment in both stream handlers said "Buffer has no meaning here", and the origin was spelled five ways across 15 call sites:SEEK_CUR,SEEK_SET,NULL,0and(void *)1. All of them now name the constant. The origin is also taken back throughintptr_trather thanint, which truncated on a 64-bit target.Behaviour preserved:
SEEK_SETis0andSEEK_CURis1, so every rename keeps the value it had.