Handle RDB version differences

Our tests for Redis in cpp run on Debian GNU/Linux 12 (bookworm) [Dockerfile].

I did a bunch of logs, and could confirm that:

  1. The file was not corrupted.
  2. The parsing went well, until after the magic string and the RDB version.
  3. 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 match opcode == 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;
}
1 Like