Fix for coverity #29409 - Use char 0 instead of NULL
[supertux.git] / src / addon / md5.cpp
index 3a95f2c..904e656 100644 (file)
@@ -47,6 +47,8 @@
 #include <stdexcept>
 
 MD5::MD5() :
+  buffer(),
+  digest(),
   finalized()
 {
   init();
@@ -99,22 +101,20 @@ void MD5::update(FILE *file) {
 
 void MD5::update(std::istream& stream) {
   uint8_t buffer_[1024];
-  int len;
 
   while (stream.good()) {
     stream.read((char*)buffer_, 1024); // note that return value of read is unusable.
-    len=stream.gcount();
+    int len = stream.gcount();
     update(buffer_, len);
   }
 }
 
 void MD5::update(std::ifstream& stream) {
   uint8_t buffer_[1024];
-  int len;
 
   while (stream.good()) {
     stream.read((char*)buffer_, 1024); // note that return value of read is unusable.
-    len=stream.gcount();
+    int len = stream.gcount();
     update(buffer_, len);
   }
 }
@@ -162,7 +162,11 @@ std::string MD5::hex_digest() {
 
   s[32]='\0';
 
-  return s;
+  // Create string from 's'
+  std::string s_str = std::string(s);
+  delete[] s;
+
+  return s_str;
 }
 
 std::ostream& operator<<(std::ostream &stream, MD5 context) {