diff --git a/ApplicationCode/Application/Tools/RiaSimWellBranchTools.cpp b/ApplicationCode/Application/Tools/RiaSimWellBranchTools.cpp index 3a90dc4bf8..e80c86d0c1 100644 --- a/ApplicationCode/Application/Tools/RiaSimWellBranchTools.cpp +++ b/ApplicationCode/Application/Tools/RiaSimWellBranchTools.cpp @@ -121,9 +121,10 @@ int RiaSimWellBranchTools::clampBranchIndex(const QString& simWellName, int bran return -1; } - if (branchIndexValue >= branches.size()) + int maxIndexValue = static_cast(branches.size()) - 1; + if (branchIndexValue > maxIndexValue) { - branchIndexValue = static_cast(branches.size()) - 1; + branchIndexValue = maxIndexValue; } return branchIndexValue;