diff --git a/src/windows/native/sun/windows/awt_Font.cpp b/src/windows/native/sun/windows/awt_Font.cpp index 7282a8f593b741b74a4c666f0deb9eed849bc9eb..7c9084915d8fed2d0e054b6f4d8c72aa3a30896f 100644 --- a/src/windows/native/sun/windows/awt_Font.cpp +++ b/src/windows/native/sun/windows/awt_Font.cpp @@ -844,11 +844,16 @@ Java_sun_awt_windows_WFontMetrics_charsWidth(JNIEnv *env, jobject self, if (str == NULL) { JNU_ThrowNullPointerException(env, "str argument"); - return NULL; + return 0; } - if ((len < 0) || (off < 0) || (len + off > (env->GetArrayLength(str)))) { + if ((len < 0) || (off < 0) || (len + off < 0) || + (len + off > (env->GetArrayLength(str)))) { JNU_ThrowArrayIndexOutOfBoundsException(env, "off/len argument"); - return NULL; + return 0; + } + + if (off == env->GetArrayLength(str)) { + return 0; } jchar *strp = new jchar[len]; @@ -880,12 +885,18 @@ Java_sun_awt_windows_WFontMetrics_bytesWidth(JNIEnv *env, jobject self, if (str == NULL) { JNU_ThrowNullPointerException(env, "bytes argument"); - return NULL; + return 0; } - if ((len < 0) || (off < 0) || (len + off > (env->GetArrayLength(str)))) { + if ((len < 0) || (off < 0) || (len + off < 0) || + (len + off > (env->GetArrayLength(str)))) { JNU_ThrowArrayIndexOutOfBoundsException(env, "off or len argument"); - return NULL; + return 0; + } + + if (off == env->GetArrayLength(str)) { + return 0; } + char *pStrBody = NULL; jint result = 0; try { @@ -893,12 +904,12 @@ Java_sun_awt_windows_WFontMetrics_bytesWidth(JNIEnv *env, jobject self, AwtFont::widthsID); if (array == NULL) { JNU_ThrowNullPointerException(env, "Can't access widths array."); - return NULL; + return 0; } pStrBody = (char *)env->GetPrimitiveArrayCritical(str, 0); if (pStrBody == NULL) { JNU_ThrowNullPointerException(env, "Can't access str bytes."); - return NULL; + return 0; } char *pStr = pStrBody + off; @@ -908,7 +919,7 @@ Java_sun_awt_windows_WFontMetrics_bytesWidth(JNIEnv *env, jobject self, if (widths == NULL) { env->ReleasePrimitiveArrayCritical(str, pStrBody, 0); JNU_ThrowNullPointerException(env, "Can't access widths."); - return NULL; + return 0; } for (; len; len--) { result += widths[*pStr++];