summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorschnetter <schnetter@17b73243-c579-4c4c-a9d2-2d5706c11dac>2005-09-04 22:15:42 +0000
committerschnetter <schnetter@17b73243-c579-4c4c-a9d2-2d5706c11dac>2005-09-04 22:15:42 +0000
commit3ffcf43599d077d25c35f48af87c0b4cbfde1224 (patch)
treeb7a38ef49ef91d7207ebd118656994691c25ccb1 /src/util
parente48e267832a3eb9b417a441900ddc5a2acaf87d9 (diff)
Ensure that the step size for integer parameter ranges is always
positive. Cast to unsigned int when checking whether the parameter value complies with the step size. Explain why this is necessary. git-svn-id: http://svn.cactuscode.org/flesh/trunk@4119 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/util')
-rw-r--r--src/util/Misc.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/util/Misc.c b/src/util/Misc.c
index 382b7226..9d92a447 100644
--- a/src/util/Misc.c
+++ b/src/util/Misc.c
@@ -439,6 +439,11 @@ int Util_IntInRange(int inval, const char *range)
/* No step given, so default to 1. */
step = 1;
}
+ if (step <= 0)
+ {
+ CCTK_Warn(1, __LINE__, __FILE__, "Flesh", "Invalid step");
+ step = 1;
+ }
/* Finally work out if the range is closed at the upper end. */
if(pmatch[5].rm_so != -1)
@@ -455,9 +460,12 @@ int Util_IntInRange(int inval, const char *range)
end_closed = 1;
}
+ /* Cast to unsigned int, because the subtraction (inval - start)
+ can overflow, and wrap-around is legal in C only for unsigned
+ types. */
if(inval >= start + !start_closed &&
inval <= end - !end_closed &&
- ! ((inval-start) % step))
+ ! (((unsigned int)inval-(unsigned int)start) % (unsigned int)step))
{
retval = 1;
}