0

I am using hiredis. hiredis has the api:

  void* redisCommand(redisContext *c, char *format, ...)

If the format is a c string contain '\0', the format is truncated. How to fix this?

luoluo
  • 5,353
  • 3
  • 30
  • 41

2 Answers2

0

C and C++ are different languages.

In C, a string, by definition, is a contiguous sequence of non-null characters followed by and including a null character terminator. Anything else is not a string.

If you are using a function which only accepts a C string, nothing else is valid and that would be a design-decision and not a "bug" requiring a "fix". If the source-code for hiredis is available to you, you might be able to gain additional insight by examining that source-code.

Shao
  • 537
  • 3
  • 7
0

use the binary safe command:

redisCommand("set %b %b", key, keyLen, value, valueLen);
luoluo
  • 5,353
  • 3
  • 30
  • 41