CBlock::WriteToDisk() properly checks ftell(3) for error return
authorJeff Garzik <jgarzik@exmulti.com>
Sun, 22 Apr 2012 17:59:24 +0000 (13:59 -0400)
committerLuke Dashjr <luke-jr+git@utopios.org>
Tue, 24 Apr 2012 05:00:15 +0000 (01:00 -0400)
Rather than storing ftell(3)'s return value -- a long -- in an
unsigned int, we store and check a properly typed temp.  Then, assured a
non-negative value, we store in nBlockPosRet.

src/main.h

index de674b5..e835cdd 100644 (file)
@@ -961,9 +961,10 @@ public:
         fileout << FLATDATA(pchMessageStart) << nSize;
 
         // Write block
-        nBlockPosRet = ftell(fileout);
-        if (nBlockPosRet == -1)
+        long fileOutPos = ftell(fileout);
+        if (fileOutPos < 0)
             return error("CBlock::WriteToDisk() : ftell failed");
+        nBlockPosRet = fileOutPos;
         fileout << *this;
 
         // Flush stdio buffers and commit to disk before returning