From f44dc926e6880777f96f884b42e4dd95f665b097 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 9 Mar 2014 10:02:07 +0100 Subject: [PATCH] - fixed uniqueTid logic - patch by Edward-San. --- src/p_mobj.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 7dc8a3f46..168d686fe 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -2726,16 +2726,15 @@ int P_FindUniqueTID(int start_tid, int limit) if (start_tid != 0) { // Do a linear search. - int end_tid = start_tid; - if (start_tid > 0 && limit > INT_MAX - start_tid + 1) - { // If 'limit+start_tid-1' overflows, clamp 'end_tid' to INT_MAX - end_tid = INT_MAX; + if (start_tid > INT_MAX-limit+1) + { // If 'limit+start_tid-1' overflows, clamp 'limit' to INT_MAX + limit = INT_MAX; } else { - end_tid += limit-1; + limit += start_tid-1; } - for (tid = start_tid; tid <= end_tid; ++tid) + for (tid = start_tid; tid <= limit; ++tid) { if (tid != 0 && !P_IsTIDUsed(tid)) {