$OpenBSD: patch-par2repairer_cpp,v 1.1.1.1 2004/01/23 05:20:48 jolan Exp $
--- par2repairer.cpp.orig	2003-05-26 13:01:26.000000000 -0500
+++ par2repairer.cpp	2004-01-21 18:06:05.000000000 -0600
@@ -341,7 +341,7 @@ bool Par2Repairer::LoadPacketsFromFile(s
           // Did we find the magic
           if (current <= limit)
           {
-            header = *(PACKET_HEADER*)current;
+            memcpy(&header, current, sizeof(header));
             break;
           }
         }
@@ -820,6 +820,9 @@ bool Par2Repairer::CheckPacketConsistenc
         continue;
       }
 
+      // Compute and store the block count from the filesize and blocksize
+      sf->second->SetBlockCount(blocksize);
+
       // Do we have a verification packet
       VerificationPacket *verificationpacket = sf->second->GetVerificationPacket();
       if (verificationpacket == 0)
@@ -916,14 +919,14 @@ bool Par2Repairer::AllocateSourceBlocks(
     Par2RepairerSourceFile *sourcefile = *sf;
     if (sourcefile)
     {
-      sourceblockcount += sourcefile->GetVerificationPacket()->BlockCount();
+      sourceblockcount += sourcefile->BlockCount();
     }
     else
     {
       // No details for this source file so we don't know what the
       // total number of source blocks is
-      sourceblockcount = 0;
-      break;
+//      sourceblockcount = 0;
+//      break;
     }
 
     ++sf;
@@ -955,16 +958,19 @@ bool Par2Repairer::AllocateSourceBlocks(
     {
       Par2RepairerSourceFile *sourcefile = *sf;
 
-      totalsize += sourcefile->GetDescriptionPacket()->FileSize();
-      u32 blockcount = sourcefile->GetVerificationPacket()->BlockCount();
+      if (sourcefile)
+      {
+        totalsize += sourcefile->GetDescriptionPacket()->FileSize();
+        u32 blockcount = sourcefile->BlockCount();
 
-      // Allocate the source and target DataBlocks to the sourcefile
-      sourcefile->SetBlocks(blocknumber, blockcount, sourceblock, targetblock, blocksize);
+        // Allocate the source and target DataBlocks to the sourcefile
+        sourcefile->SetBlocks(blocknumber, blockcount, sourceblock, targetblock, blocksize);
 
-      blocknumber++;
+        blocknumber++;
 
-      sourceblock += blockcount;
-      targetblock += blockcount;
+        sourceblock += blockcount;
+        targetblock += blockcount;
+      }
 
       ++sf;
       ++filenumber;
@@ -1069,7 +1075,7 @@ bool Par2Repairer::VerifySourceFiles(voi
       // Was this one of the recoverable files
       if (filenumber < mainpacket->RecoverableFileCount())
       {
-        cerr << "No details available for recoverable file number " << filenumber+1 << ". Recovery will not be possible." << endl;
+        cerr << "No details available for recoverable file number " << filenumber+1 << "." << endl << "Recovery will not be possible." << endl;
 
         // Set error but let verification of other files continue
         finalresult = false;
@@ -1676,42 +1682,49 @@ void Par2Repairer::UpdateVerificationRes
   {
     Par2RepairerSourceFile *sourcefile = *sf;
 
-    // Was a perfect match for the file found
-    if (sourcefile->GetCompleteFile() != 0)
+    if (sourcefile)
     {
-      // Is it the target file or a different one
-      if (sourcefile->GetCompleteFile() == sourcefile->GetTargetFile())
+      // Was a perfect match for the file found
+      if (sourcefile->GetCompleteFile() != 0)
       {
-        completefilecount++;
+        // Is it the target file or a different one
+        if (sourcefile->GetCompleteFile() == sourcefile->GetTargetFile())
+        {
+          completefilecount++;
+        }
+        else
+        {
+          renamedfilecount++;
+        }
+
+        availableblockcount += sourcefile->BlockCount();
       }
       else
       {
-        renamedfilecount++;
-      }
+        // Count the number of blocks that have been found
+        vector<DataBlock>::iterator sb = sourcefile->SourceBlocks();
+        for (u32 blocknumber=0; blocknumber<sourcefile->BlockCount(); ++blocknumber, ++sb)
+        {
+          DataBlock &datablock = *sb;
+          
+          if (datablock.IsSet())
+            availableblockcount++;
+        }
 
-      availableblockcount += sourcefile->BlockCount();
+        // Does the target file exist
+        if (sourcefile->GetTargetExists())
+        {
+          damagedfilecount++;
+        }
+        else
+        {
+          missingfilecount++;
+        }
+      }
     }
     else
     {
-      // Count the number of blocks that have been found
-      vector<DataBlock>::iterator sb = sourcefile->SourceBlocks();
-      for (u32 blocknumber=0; blocknumber<sourcefile->BlockCount(); ++blocknumber, ++sb)
-      {
-        DataBlock &datablock = *sb;
-        
-        if (datablock.IsSet())
-          availableblockcount++;
-      }
-
-      // Does the target file exist
-      if (sourcefile->GetTargetExists())
-      {
-        damagedfilecount++;
-      }
-      else
-      {
-        missingfilecount++;
-      }
+      missingfilecount++;
     }
 
     ++filenumber;
