--- old/src/hotspot/share/utilities/stringUtils.cpp 2018-05-31 01:58:36.352352722 -0400 +++ new/src/hotspot/share/utilities/stringUtils.cpp 2018-05-31 01:58:34.904268866 -0400 @@ -23,6 +23,7 @@ */ #include "precompiled.hpp" +#include "utilities/debug.hpp" #include "utilities/stringUtils.hpp" int StringUtils::replace_no_expand(char* string, const char* from, const char* to) { @@ -43,9 +44,16 @@ } double StringUtils::similarity(const char* str1, size_t len1, const char* str2, size_t len2) { - size_t total = len1 + len2; + assert(str1 != NULL && str2 != NULL, "sanity"); + size_t total = len1 + len2; size_t hit = 0; + + // filter out zero-length strings else we will underflow on len-1 below + if (len1 == 0 || len2 == 0) { + return 0.0; + } + for (size_t i = 0; i < len1 - 1; i++) { for (size_t j = 0; j < len2 - 1; j++) { if ((str1[i] == str2[j]) && (str1[i+1] == str2[j+1])) {