C++ Converting binary data to a hex string and back

后端 未结 3 1814
谎友^
谎友^ 2021-01-25 10:35

I have a matching pair of static functions in a utility class that I use to convert between binary data (unsigned characters) and it\'s string representation (a-f and 0-9). They

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-25 11:13

    Your sscanf will write an unsigned int into the memory location you give it. Typically, an unsigned int is 4 or 8 bytes long, while you only intend to provide 1 byte. So at the end you're running flat-out over the end of your dynamic array.

    By the way, your code is very far removed from modern, idiomatic C++ - it's essentially just a glorified C mess. I strongly suggest rewriting it in the spirit of C++.

提交回复
热议问题