-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
See below.
Chris
On Thu, 9 May 2013 20:13:34 -0700 (PDT)
Murray <
in...@murrawhip.net> wrote:
> 7. const char * SHA256(const char * argv)
> 8. {
> 9. CryptoPP::SHA256 hash;
> 10. byte digest[ CryptoPP::SHA256::DIGESTSIZE ];
> 11. std::string input = std::string(argv);
> 12.
> 13. hash.CalculateDigest( digest, (const byte
> *)input.c_str(), input.length() );
> 14.
> 15. CryptoPP::HexEncoder encoder;
> 16. std::string output;
> 17. encoder.Attach(new CryptoPP::StringSink( output ));
> 18. encoder.Put( digest, sizeof(digest) );
> 19. encoder.MessageEnd();
> 20. return output.c_str();
On this line, you are returning a pointer to a member of a local
variable. The variable output is a local and will therefore be
destroyed on return, which also deallocates the internal storage used
to hold the c_str. You then use the c_str after it has been freed. You
should return an std::string instead.
> 21. }
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)
iF4EAREIAAYFAlGNOGUACgkQnfE3lq0v9IzkPAD/a5oKJOUwVqWuWKTUEcJstJXb
I9ujNtRlML76OP2tjm8A/ivx+xaKLyeKj7Wiw9iwHgkUy8O0dEg67LhOBZ8kUxA7
=a8Fl
-----END PGP SIGNATURE-----