From d465ad8beade866e0d3bc6e2545f7429bf171b76 Mon Sep 17 00:00:00 2001 From: Mark Abraham Date: Fri, 9 Dec 2016 03:47:09 +1100 Subject: [PATCH] Fix logic of TRR reading Commit f7d4d019 introduced a bug where TRR reading reaching the end of the file was indistinguishable from a reading error or a magic-number error. This is now fixed, restoring the end-of-file behaviour that existed before f7d4d019, while retaining the wrong-magic-number behaviour that it introduced. Refs #1926 Change-Id: Ic8540846c481f022bc6ae7b774794792c8c7a523 --- src/gromacs/fileio/trrio.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/gromacs/fileio/trrio.cpp b/src/gromacs/fileio/trrio.cpp index 2890557224..87cddfdd52 100644 --- a/src/gromacs/fileio/trrio.cpp +++ b/src/gromacs/fileio/trrio.cpp @@ -82,6 +82,14 @@ static int nFloatSize(gmx_trr_header_t *sh) return nflsize; } +/* Returns whether a valid frame header was read. Upon exit, *bOK is + TRUE if a normal outcome resulted. Usually that is the same thing, + but encountering the end of the file before reading the magic + integer is a normal outcome for TRR reading, and it does not + produce a valid frame header, so the values differ in that case. + That does not exclude the possibility of a reading error between + frames, but the trajectory-handling infrastructure needs an + overhaul before we can handle that. */ static gmx_bool do_trr_frame_header(t_fileio *fio, bool bRead, gmx_trr_header_t *sh, gmx_bool *bOK) { @@ -94,9 +102,11 @@ do_trr_frame_header(t_fileio *fio, bool bRead, gmx_trr_header_t *sh, gmx_bool *b if (!gmx_fio_do_int(fio, magic)) { - // Failed to read an integer, which should be the magic number - *bOK = FALSE; - return *bOK; + /* Failed to read an integer, which should be the magic + number, which usually means we've reached the end + of the file (but could be an I/O error that we now + might mishandle). */ + return FALSE; } if (magic != magicValue) { -- 2.11.4.GIT