diff options
Diffstat (limited to 'src/util/Misc.c')
-rw-r--r-- | src/util/Misc.c | 10 |
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; } |