Fix for coverity #29409 - Use char 0 instead of NULL
[supertux.git] / src / addon / md5.cpp
index cc5e83c..904e656 100644 (file)
@@ -47,6 +47,8 @@
 #include <stdexcept>
 
 MD5::MD5() :
+  buffer(),
+  digest(),
   finalized()
 {
   init();
@@ -89,33 +91,31 @@ void MD5::update (uint8_t* input, uint32_t input_length) {
 }
 
 void MD5::update(FILE *file) {
-  uint8_t buffer[1024];
+  uint8_t buffer_[1024];
   int len;
 
-  while ((len=fread(buffer, 1, 1024, file))) update(buffer, len);
+  while ((len=fread(buffer_, 1, 1024, file))) update(buffer_, len);
 
   fclose (file);
 }
 
 void MD5::update(std::istream& stream) {
-  uint8_t buffer[1024];
-  int len;
+  uint8_t buffer_[1024];
 
   while (stream.good()) {
-    stream.read((char*)buffer, 1024); // note that return value of read is unusable.
-    len=stream.gcount();
-    update(buffer, len);
+    stream.read((char*)buffer_, 1024); // note that return value of read is unusable.
+    int len = stream.gcount();
+    update(buffer_, len);
   }
 }
 
 void MD5::update(std::ifstream& stream) {
-  uint8_t buffer[1024];
-  int len;
+  uint8_t buffer_[1024];
 
   while (stream.good()) {
-    stream.read((char*)buffer, 1024); // note that return value of read is unusable.
-    len=stream.gcount();
-    update(buffer, len);
+    stream.read((char*)buffer_, 1024); // note that return value of read is unusable.
+    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) {