Our tests for Redis in cpp run on Debian GNU/Linux 12 (bookworm)
[Dockerfile].
I did a bunch of logs, and could confirm that:
- The file was not corrupted.
- The parsing went well, until after the magic string and the RDB version.
- Everything from this point was ignored till the end of the file.
So a crucial question is:
Can the code read the next byte
0xFA
correctly, and matchopcode == 0xFA
?
The result is no and no.
The reason is that char is signed by default on most platforms, meaning char opcode
interprets 0xFA as -6
, thus ignoring opcode (-6) == 0xFA (250)
Do you by any chance use an ARM-based machine, where char could be unsigned
by default? @AlRodriguezGar14
You can do this to find out:
char opcode = 0xFA;
std::cout << "opcode as int: " << int(opcode) << std::endl;
if (std::is_signed<decltype(opcode)>::value)
{
std::cout << "opcode is signed." << std::endl;
}
else
{
std::cout << "opcode is unsigned." << std::endl;
}