From 20d0ca7a93ffe72dd8cd23223fc08c4bac934f43 Mon Sep 17 00:00:00 2001 From: knarf Date: Mon, 3 Dec 2012 04:41:30 +0000 Subject: Cactus allows for negative error level Currently, Cactus allows to set a negative error level through the command line option. This leads to CCTK_WARN(0,"") not necessarily aborting. While this is not wrong by itself, a lot of code assumes an abort at that point. This patch changes CCTKi_SetErrorLevel() to only accept non-negative error levels and to change the command-parsing code to give an error message for that case as well. git-svn-id: http://svn.cactuscode.org/flesh/trunk@4923 17b73243-c579-4c4c-a9d2-2d5706c11dac --- src/main/CommandLine.c | 12 +++++++++++- src/main/WarnLevel.c | 8 +++++++- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/CommandLine.c b/src/main/CommandLine.c index 6b4b1f2e..82a118e5 100644 --- a/src/main/CommandLine.c +++ b/src/main/CommandLine.c @@ -379,7 +379,17 @@ void CCTKi_CommandLineErrorLevel (const char *argument) errorlevel = strtol (argument, &endptr, 10); if (endptr && *endptr == 0) { - CCTKi_SetErrorLevel (errorlevel); + if (errorlevel < 0) + { + CCTK_VWarn (0, __LINE__, __FILE__, "Cactus", + "Error level cannot be negative, but %d was requested.", + (int)errorlevel); + CCTK_Exit (NULL, 1); + } + else + { + CCTKi_SetErrorLevel (errorlevel); + } } else { diff --git a/src/main/WarnLevel.c b/src/main/WarnLevel.c index 9e1cd221..52fa0f5a 100644 --- a/src/main/WarnLevel.c +++ b/src/main/WarnLevel.c @@ -1109,7 +1109,13 @@ int CCTKi_SetErrorLevel (int level) { int retval; - if (level <= warning_level) + if (level < 0) + { + CCTK_VWarn (3, __LINE__, __FILE__, "Cactus", + "Error level cannot be negative (%d requested)", level); + retval = 0; + } + else if (level <= warning_level) { if (error_level != level) { -- cgit v1.2.3