From 0412cfcbcdd7224f80a80180a946f0fdd28c3afc Mon Sep 17 00:00:00 2001 From: Chen YANG Date: Wed, 25 Jul 2012 13:27:40 +0800 Subject: [PATCH] Add shortcut to avoid potential divide by zero in some case Change-Id: If4b34c95402daf8ebcc28736edfb2012553aa57c --- libs/hwui/FontRenderer.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/hwui/FontRenderer.cpp b/libs/hwui/FontRenderer.cpp index 0d6e62ac3db93..5fdbc11d0e5eb 100644 --- a/libs/hwui/FontRenderer.cpp +++ b/libs/hwui/FontRenderer.cpp @@ -946,6 +946,11 @@ void FontRenderer::appendRotatedMeshQuad(float x1, float y1, float u1, float v1, uint32_t FontRenderer::getRemainingCacheCapacity() { uint32_t remainingCapacity = 0; float totalPixels = 0; + + //avoid divide by zero if the size is 0 + if (mCacheLines.size() == 0) { + return 0; + } for(uint32_t i = 0; i < mCacheLines.size(); i ++) { remainingCapacity += (mCacheLines[i]->mMaxWidth - mCacheLines[i]->mCurrentCol); totalPixels += mCacheLines[i]->mMaxWidth;