< prev index next >

src/java.desktop/share/native/libawt/java2d/loops/TransformHelper.c

Print this page




 390     if (numedges <= 0) {
 391         pEdges = NULL;
 392     } else if (!JNU_IsNull(env, edgeArray)) {
 393         /*
 394          * Ideally Java should allocate an array large enough, but if
 395          * we ever have a miscommunication about the number of edge
 396          * lines, or if the Java array calculation should overflow to
 397          * a positive number and succeed in allocating an array that
 398          * is too small, we need to verify that it can still hold the
 399          * number of integers that we plan to store to be safe.
 400          */
 401         jsize edgesize = (*env)->GetArrayLength(env, edgeArray);
 402         /* (edgesize/2 - 1) should avoid any overflow or underflow. */
 403         pEdges = (((edgesize / 2) - 1) >= numedges)
 404             ? (*env)->GetPrimitiveArrayCritical(env, edgeArray, NULL)
 405             : NULL;
 406     } else if (numedges > MAXEDGES) {
 407         /* numedges variable (jlong) can be at most ((1<<32)-1) */
 408         /* memsize can overflow a jint, but not a jlong */
 409         jlong memsize = ((numedges * 2) + 2) * sizeof(*pEdges);
 410         pEdges = (memsize == ((size_t) memsize))
 411             ? malloc((size_t) memsize)
 412             : NULL;
 413     } else {
 414         pEdges = edgebuf;
 415     }
 416 
 417     if (pEdges == NULL) {
 418         if (!(*env)->ExceptionCheck(env) && numedges > 0) {
 419             JNU_ThrowInternalError(env, "Unable to allocate edge list");
 420         }
 421         SurfaceData_InvokeUnlock(env, dstOps, &dstInfo);
 422         SurfaceData_InvokeUnlock(env, srcOps, &srcInfo);
 423         /* edgeArray should already contain zeros for min/maxy */
 424         return;
 425     }
 426 
 427 
 428     if (!Region_IsEmpty(&clipInfo)) {
 429         srcOps->GetRasInfo(env, srcOps, &srcInfo);
 430         dstOps->GetRasInfo(env, dstOps, &dstInfo);
 431         if (srcInfo.rasBase == NULL || dstInfo.rasBase == NULL) {
 432             pEdges[0] = pEdges[1] = 0;




 390     if (numedges <= 0) {
 391         pEdges = NULL;
 392     } else if (!JNU_IsNull(env, edgeArray)) {
 393         /*
 394          * Ideally Java should allocate an array large enough, but if
 395          * we ever have a miscommunication about the number of edge
 396          * lines, or if the Java array calculation should overflow to
 397          * a positive number and succeed in allocating an array that
 398          * is too small, we need to verify that it can still hold the
 399          * number of integers that we plan to store to be safe.
 400          */
 401         jsize edgesize = (*env)->GetArrayLength(env, edgeArray);
 402         /* (edgesize/2 - 1) should avoid any overflow or underflow. */
 403         pEdges = (((edgesize / 2) - 1) >= numedges)
 404             ? (*env)->GetPrimitiveArrayCritical(env, edgeArray, NULL)
 405             : NULL;
 406     } else if (numedges > MAXEDGES) {
 407         /* numedges variable (jlong) can be at most ((1<<32)-1) */
 408         /* memsize can overflow a jint, but not a jlong */
 409         jlong memsize = ((numedges * 2) + 2) * sizeof(*pEdges);
 410         pEdges = (memsize > 0) ? malloc((size_t) memsize) : NULL;


 411     } else {
 412         pEdges = edgebuf;
 413     }
 414 
 415     if (pEdges == NULL) {
 416         if (!(*env)->ExceptionCheck(env) && numedges > 0) {
 417             JNU_ThrowInternalError(env, "Unable to allocate edge list");
 418         }
 419         SurfaceData_InvokeUnlock(env, dstOps, &dstInfo);
 420         SurfaceData_InvokeUnlock(env, srcOps, &srcInfo);
 421         /* edgeArray should already contain zeros for min/maxy */
 422         return;
 423     }
 424 
 425 
 426     if (!Region_IsEmpty(&clipInfo)) {
 427         srcOps->GetRasInfo(env, srcOps, &srcInfo);
 428         dstOps->GetRasInfo(env, dstOps, &dstInfo);
 429         if (srcInfo.rasBase == NULL || dstInfo.rasBase == NULL) {
 430             pEdges[0] = pEdges[1] = 0;


< prev index next >