Commit f7d4d019 authored by Mark Abraham's avatar Mark Abraham
Browse files

Fix trr magic number reading

The trr header-reading routine returned an "OK" value if the magic
number was wrong, which might lead to chaotic results everywhere,
because checking of return values tends not to happen (even when
they're right). Other GROMACS magic-number reading routines tend to
give a fatal error if the the number is wrong, e.g. by reading a file
written in wrong endianness. (This should never be a thing for XDR
files, which are defined to be big endian, but such code has existed.)

This change adds/restores that behaviour to trr reading, along
with separating the behaviour of failing to read a magic integer
from reading one that doesn't match.

Fixes #1926

Change-Id: I3cdd8ae9172e3b95fc232d8fa31a442d239233db
parent d714741d
......@@ -48,7 +48,6 @@
#include "gromacs/utility/smalloc.h"
#define BUFSIZE 128
#define GROMACS_MAGIC 1993
static int nFloatSize(gmx_trr_header_t *sh)
......@@ -86,15 +85,24 @@ static int nFloatSize(gmx_trr_header_t *sh)
static gmx_bool
do_trr_frame_header(t_fileio *fio, bool bRead, gmx_trr_header_t *sh, gmx_bool *bOK)
int magic = GROMACS_MAGIC;
static gmx_bool bFirst = TRUE;
const int magicValue = 1993;
int magic = magicValue;
static gmx_bool bFirst = TRUE;
char buf[256];
*bOK = TRUE;
if (!gmx_fio_do_int(fio, magic) || magic != GROMACS_MAGIC)
if (!gmx_fio_do_int(fio, magic))
return FALSE;
// Failed to read an integer, which should be the magic number
return *bOK;
if (magic != magicValue)
gmx_fatal(FARGS, "Failed to find GROMACS magic number in trr frame header, so this is not a trr file!\n");
return *bOK;
if (bRead)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment