ldb: fix dump command to pad HEX output chars with 0.

Summary: The old code was omitting the 0 if the char is less than 16.

Test Plan:
Tried the following program:
int main() {
  unsigned char c = 1;
  printf("%X\n", c);
  printf("%02X\n", c);
  return 0;
}
The output is:
1
01

Reviewers: dhruba

Reviewed By: dhruba

CC: leveldb

Differential Revision: https://reviews.facebook.net/D7437
main
Zheng Shao 12 years ago
parent 7dc8bb710e
commit 3d9ff0e921
  1. 4
      util/ldb_cmd.cc

@ -245,12 +245,12 @@ void DBDumper::DoCommand() {
if (hex_output_) {
std::string str = iter->key().ToString();
for (unsigned int i = 0; i < str.length(); ++i) {
fprintf(stdout, "%X", str[i]);
fprintf(stdout, "%02X", (unsigned char)str[i]);
}
fprintf(stdout, " ==> ");
str = iter->value().ToString();
for (unsigned int i = 0; i < str.length(); ++i) {
fprintf(stdout, "%X", str[i]);
fprintf(stdout, "%02X", (unsigned char)str[i]);
}
fprintf(stdout, "\n");
} else {

Loading…
Cancel
Save