From 909f8293c8fbbd416d16b793b61322ab0344664f Mon Sep 17 00:00:00 2001 From: Stefan Fleischmann Date: Fri, 8 Aug 2014 17:14:17 +0200 Subject: [PATCH] Avoid stack overflow on Windows with CMake > 2.8.10.2 CMake used to add "/STACK:10000000" to the default linker flags. That was removed in version 2.8.11-rc1. The default value used by MSVC is apparently too small because mdrun crashes with a stack overflow when built on Windows with MSVC or ICC and CMake newer than 2.8.10.2. The issue is already fixed in GROMACS 5.0 and master by I1e9858ae3. This is a backport for release-4-6 of that commit. Change-Id: Ib9238e513da8e86049d9e56c82262055d3c8b349 --- src/gmxlib/gmxfio.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/gmxlib/gmxfio.c b/src/gmxlib/gmxfio.c index e9ede13221..69adcea129 100644 --- a/src/gmxlib/gmxfio.c +++ b/src/gmxlib/gmxfio.c @@ -2,12 +2,11 @@ * This file is part of the GROMACS molecular simulation package. * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. - * Copyright (c) 2001-2004, The GROMACS development team, - * check out http://www.gromacs.org for more information. - * Copyright (c) 2012,2013, by the GROMACS development team, led by - * David van der Spoel, Berk Hess, Erik Lindahl, and including many - * others, as listed in the AUTHORS file in the top-level source - * directory and at http://www.gromacs.org. + * Copyright (c) 2001-2004, The GROMACS development team. + * Copyright (c) 2013,2014, by the GROMACS development team, led by + * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, + * and including many others, as listed in the AUTHORS file in the + * top-level source directory and at http://www.gromacs.org. * * GROMACS is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -683,11 +682,11 @@ static int gmx_fio_int_get_file_md5(t_fileio *fio, gmx_off_t offset, { /*1MB: large size important to catch almost identical files */ #define CPT_CHK_LEN 1048576 - md5_state_t state; - unsigned char buf[CPT_CHK_LEN]; - gmx_off_t read_len; - gmx_off_t seek_offset; - int ret = -1; + md5_state_t state; + unsigned char *buf; + gmx_off_t read_len; + gmx_off_t seek_offset; + int ret = -1; seek_offset = offset - CPT_CHK_LEN; if (seek_offset < 0) @@ -710,6 +709,7 @@ static int gmx_fio_int_get_file_md5(t_fileio *fio, gmx_off_t offset, return -1; } + snew(buf, CPT_CHK_LEN); /* the read puts the file position back to offset */ if ((gmx_off_t)fread(buf, 1, read_len, fio->fp) != read_len) { @@ -758,12 +758,10 @@ static int gmx_fio_int_get_file_md5(t_fileio *fio, gmx_off_t offset, md5_init(&state); md5_append(&state, buf, read_len); md5_finish(&state, digest); - return read_len; - } - else - { - return ret; + ret = read_len; } + sfree(buf); + return ret; } -- 2.22.0