-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

See below.

Chris

On Thu, 9 May 2013 20:13:34 -0700 (PDT)
Murray <[email protected]> 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-----

-- 
-- 
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
--- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to