workaround valgrind warnings
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 19 Apr 2010 14:49:13 +0200
changeset 6244 ec4b512688d8
parent 6243 a597d6d2da85
child 6246 c21414b217d3
workaround valgrind warnings
src/common/pcap-file.cc
--- a/src/common/pcap-file.cc	Sat Apr 17 17:36:53 2010 +0100
+++ b/src/common/pcap-file.cc	Mon Apr 19 14:49:13 2010 +0200
@@ -417,6 +417,11 @@
   m_file.read ((char *)&header.m_inclLen, sizeof(header.m_inclLen));
   m_file.read ((char *)&header.m_origLen, sizeof(header.m_origLen));
 
+  if (m_file.fail ())
+    {
+      return;
+    }
+
   if (m_swapMode)
     {
       Swap (&header, &header);
@@ -470,12 +475,18 @@
   uint32_t readLen1, readLen2;
   bool diff = false;
   
-  while (!pcap1.Eof () && !pcap2.Eof ()
-         && !pcap1.Fail () && !pcap2.Fail ())
+  while (!pcap1.Eof () && !pcap2.Eof ())
     {
       pcap1.Read (data1, snapLen, tsSec1, tsUsec1, inclLen1, origLen1, readLen1);
       pcap2.Read (data2, snapLen, tsSec2, tsUsec2, inclLen2, origLen2, readLen2);
 
+      bool bad = pcap1.Fail () || pcap2.Fail ();
+      if (bad)
+        {
+          diff = true;
+          break;
+        }
+
       if (tsSec1 != tsSec2 || tsUsec1 != tsUsec2)
         {
           diff = true; // Next packet timestamps do not match