From a9fb8c63025596d1610e31f2d027fa5c99a90a18 Mon Sep 17 00:00:00 2001
From: Marcel Loose <loose@astron.nl>
Date: Mon, 13 Jan 2014 15:19:07 +0000
Subject: [PATCH] Task #5291: Fixed obscure bug in FastFileStream. Obscure in
 the sense that the code was plain wrong, but for reasons beyond my
 comprehension, the old GCC compiler generated correct(?) code.

---
 RTCP/Cobalt/OutputProc/src/FastFileStream.cc | 7 ++++---
 RTCP/Cobalt/OutputProc/src/FastFileStream.h  | 4 ++--
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/RTCP/Cobalt/OutputProc/src/FastFileStream.cc b/RTCP/Cobalt/OutputProc/src/FastFileStream.cc
index 7398ee58ea4..8db289c0d2c 100644
--- a/RTCP/Cobalt/OutputProc/src/FastFileStream.cc
+++ b/RTCP/Cobalt/OutputProc/src/FastFileStream.cc
@@ -80,13 +80,14 @@ namespace LOFAR
     {
       if (remainder) {
         // pad with zeroes
+        size_t nrpadbytes = alignment - remainder;
         ensureBuffer(alignment);
-        memset(buffer.get() + remainder, 0, alignment - remainder);
+        memset(buffer.get() + remainder, 0, nrpadbytes);
         forceWrite(buffer, alignment);
 
         remainder = 0;
 
-        return alignment;
+        return nrpadbytes;
       }
 
       return 0;
@@ -176,7 +177,7 @@ namespace LOFAR
 
       // get rid of the old remainder first
       if (bytes + remainder >= alignment) {
-        bytes -= (writeRemainder() - remainder);
+        bytes -= writeRemainder();
 
         if (bytes >= alignment ) {
           // skip whole number of blocks
diff --git a/RTCP/Cobalt/OutputProc/src/FastFileStream.h b/RTCP/Cobalt/OutputProc/src/FastFileStream.h
index 966167032f7..5b1c4335f83 100644
--- a/RTCP/Cobalt/OutputProc/src/FastFileStream.h
+++ b/RTCP/Cobalt/OutputProc/src/FastFileStream.h
@@ -43,9 +43,9 @@ namespace LOFAR
       virtual size_t size();
 
       // formally, the required alignment for O_DIRECT is determined by the file system
-      static const unsigned alignment = 512;
+      static const size_t alignment = 512;
     private:
-      // writes the remainder, padded with zeros if needed. Returns the number of bytes written.
+      // writes the remainder, padded with zeros if needed. Returns the number of zero-pad bytes written.
       size_t writeRemainder();
 
       // we only support writing
-- 
GitLab