if (start < end && (aLength - start) > 0)
if ((start < end) && ((aLength - start) > 0))
nsTextFrame::PaintTextDecorations(nsIRenderingContext& aRenderingContext,                                  nsIStyleContext* aStyleContext,                                  TextStyle& aTextStyle,                                  nscoord aX, nscoord aY, nscoord aWidth,                                  PRUnichar *aText, /*=nsnull*/                                  SelectionDetails *aDetails,/*= nsnull*/                                  PRUint32 aIndex,  /*= 0*/                                  PRUint32 aLength, /*= 0*/                                  const nscoord* aSpacing /* = nsnull*/ ){  nscolor overColor;  nscolor underColor;  nscolor strikeColor;  nsIStyleContext*  context = aStyleContext;  PRUint8 decorations = aTextStyle.mFont->mFont.decorations;  PRUint8 decorMask = decorations;  NS_ADDREF(context);  do {  // find decoration colors    const nsStyleText* styleText =       (const nsStyleText*)context->GetStyleData(eStyleStruct_Text);    if (decorMask & styleText->mTextDecoration) {  // a decoration defined here      const nsStyleColor* styleColor =        (const nsStyleColor*)context->GetStyleData(eStyleStruct_Color);      if (NS_STYLE_TEXT_DECORATION_UNDERLINE & decorMask & styleText->mTextDecoration) {        underColor = styleColor->mColor;        decorMask &= ~NS_STYLE_TEXT_DECORATION_UNDERLINE;      }      if (NS_STYLE_TEXT_DECORATION_OVERLINE & decorMask & styleText->mTextDecoration) {        overColor = styleColor->mColor;        decorMask &= ~NS_STYLE_TEXT_DECORATION_OVERLINE;      }      if (NS_STYLE_TEXT_DECORATION_LINE_THROUGH & decorMask & styleText->mTextDecoration) {        strikeColor = styleColor->mColor;        decorMask &= ~NS_STYLE_TEXT_DECORATION_LINE_THROUGH;      }    }    if (0 != decorMask) {      nsIStyleContext*  lastContext = context;      context = context->GetParent();      NS_RELEASE(lastContext);    }  } while ((nsnull != context) && (0 != decorMask));  NS_IF_RELEASE(context);  nscoord offset;  nscoord size;  nscoord baseline;  aTextStyle.mNormalFont->GetMaxAscent(baseline);  if (decorations & (NS_FONT_DECORATION_OVERLINE | NS_FONT_DECORATION_UNDERLINE)) {    aTextStyle.mNormalFont->GetUnderline(offset, size);    if (decorations & NS_FONT_DECORATION_OVERLINE) {      aRenderingContext.SetColor(overColor);      aRenderingContext.FillRect(aX, aY, aWidth, size);    }    if (decorations & NS_FONT_DECORATION_UNDERLINE) {      aRenderingContext.SetColor(underColor);      aRenderingContext.FillRect(aX, aY + baseline - offset, aWidth, size);    }  }  if (decorations & NS_FONT_DECORATION_LINE_THROUGH) {    aTextStyle.mNormalFont->GetStrikeout(offset, size);    aRenderingContext.SetColor(strikeColor);    aRenderingContext.FillRect(aX, aY + baseline - offset, aWidth, size);  }  if (aDetails){    nsRect rect;    GetRect(rect);    PRInt32 startOffset = 0;    PRInt32 textWidth = 0;    while(aDetails){      PRInt32 start = PR_MAX(0,(aDetails->mStart - (PRInt32)aIndex));      PRInt32 end = PR_MIN((PRInt32)aLength,(aDetails->mEnd - (PRInt32)aIndex));      PRInt32 i;      if (start < end && (aLength - start) > 0)      {        //aDetails allready processed to have offsets from frame start not content offsets        if (start < end){          if (aLength == 1)            textWidth = aWidth;          else {            if (aDetails->mStart > 0){              if (aSpacing)              {                for (i = 0; i < start;i ++){                  startOffset += *aSpacing ++;                }              }              else                aRenderingContext.GetWidth(aText, start, startOffset);            }            if (aSpacing){              for (i = start; i < end;i ++){                textWidth += *aSpacing ++;              }            }            else              aRenderingContext.GetWidth(aText + start,                                           PRUint32(end - start), textWidth);            }          switch (aDetails->mType)          {          case SELECTION_NORMAL:{//// XOR InvertRect is currently implemented only in the unix and windows// rendering contexts.  When other platforms implement InvertRect(), they// can be added here.  Eventually this #ifdef should die.//// For platforms that dont implement InvertRect(), the selection will be // a non-filled rectangle.#ifdef USE_INVERT_FOR_SELECTION              aRenderingContext.SetColor(NS_RGB(255,255,255));              aRenderingContext.InvertRect(aX + startOffset, aY, textWidth, rect.height);#else              aRenderingContext.SetColor(NS_RGB(0,0,0));              aRenderingContext.DrawRect(aX + startOffset, aY, textWidth, rect.height);#endif                                }break;           case SELECTION_SPELLCHECK:{              aTextStyle.mNormalFont->GetUnderline(offset, size);              aRenderingContext.SetColor(NS_RGB(255,0,0));              aRenderingContext.FillRect(aX + startOffset, aY + baseline - offset, textWidth, size);                                }break;          case SELECTION_IME_SELECTEDRAWTEXT:{#ifdef USE_INVERT_FOR_SELECTION              aRenderingContext.SetColor(NS_RGB(255,255,255));              aRenderingContext.InvertRect(aX + startOffset, aY, textWidth, rect.height);#else              aRenderingContext.SetColor(NS_RGB(255,255,128));              aRenderingContext.DrawRect(aX + startOffset, aY, textWidth, rect.height);#endif                      aTextStyle.mNormalFont->GetUnderline(offset, size);              aRenderingContext.SetColor(NS_RGB(189,33,66));              aRenderingContext.FillRect(aX + startOffset+size, aY + baseline - offset+size, textWidth-2*size, size);                                }break;          case SELECTION_IME_RAWINPUT:{              aTextStyle.mNormalFont->GetUnderline(offset, size);              aRenderingContext.SetColor(NS_RGB(189,33,66));              aRenderingContext.FillRect(aX + startOffset+size, aY + baseline - offset+size, textWidth-2*size, size);                                }break;          case SELECTION_IME_SELECTEDCONVERTEDTEXT:{#ifdef USE_INVERT_FOR_SELECTION              aRenderingContext.SetColor(NS_RGB(255,255,255));              aRenderingContext.InvertRect(aX + startOffset, aY, textWidth, rect.height);#else              aRenderingContext.SetColor(NS_RGB(255,255,128));              aRenderingContext.DrawRect(aX + startOffset, aY, textWidth, rect.height);#endif        			  aTextStyle.mNormalFont->GetUnderline(offset, size);              aRenderingContext.SetColor(NS_RGB(189,33,66));              aRenderingContext.FillRect(aX + startOffset+size, aY + baseline - offset, textWidth-2*size, size*2);                                }break;          case SELECTION_IME_CONVERTEDTEXT:{              aTextStyle.mNormalFont->GetUnderline(offset, size);              aRenderingContext.SetColor(NS_RGB(189,33,66));              aRenderingContext.FillRect(aX + startOffset+size, aY + baseline - offset, textWidth-2*size, size*2);                                }break;          default:            NS_ASSERTION(0,"what type of selection do i not know about?");            break;          }        }      }      aDetails = aDetails->mNext;    }  }}