engine/src/PodcastUtils.cpp
branchRCL_3
changeset 369 c683165bec63
parent 333 c80c7fb835c2
--- a/engine/src/PodcastUtils.cpp	Tue Nov 16 10:26:34 2010 +0000
+++ b/engine/src/PodcastUtils.cpp	Tue Nov 16 13:05:42 2010 +0000
@@ -118,8 +118,9 @@
 	DP("    change HTML encoded chars to unicode");
 	startPos = str.Locate('&');
 	endPos = str.Locate(';');
-	while (startPos != KErrNotFound && endPos != KErrNotFound && endPos > startPos)
+	while (startPos != KErrNotFound && endPos != KErrNotFound && endPos > startPos && endPos < str.Length())
 		{
+//		DP2("startPos=%d, endPos=%d", startPos, endPos);
 		TPtrC ptr(str.Mid(startPos+1, endPos-startPos));
 		// check for whitespace
 		if (ptr.Locate(' ') == KErrNotFound)
@@ -162,10 +163,9 @@
 				_LIT(KQuot, "quot;");
 				_LIT(KNbsp, "nbsp;");
 				_LIT(KCopy, "copy;");
-				
+
 				// copy start of string
 				tmp.Copy(str.Left(startPos));
-				
 				if (ptr.CompareF(KAmp) == 0)
 					{
 					tmp.Append('&');
@@ -182,27 +182,26 @@
 					{
 					tmp.Append('\xA9');
 					}
-				
 				// copy end of string
 				tmp.Append(str.Mid(endPos+1));
 				str.Copy(tmp);
 				}
 			}
 		
-		TInt newPos = str.Mid(startPos+1).Locate('&');
-		
-		if (newPos != KErrNotFound)
-			{
-			startPos = startPos+1 + newPos;
-			endPos = str.Locate(';');
-			}
-		else
-			{
-			startPos = KErrNotFound;
-			endPos = KErrNotFound;
+		if (startPos+1 <= str.Length()) {
+			TInt newPos = str.Mid(startPos+1).Locate('&');
+			if (newPos != KErrNotFound)
+				{
+				startPos = startPos+1 + newPos;
+				endPos = str.Locate(';');
+				}
+			else
+				{
+				startPos = KErrNotFound;
+				endPos = KErrNotFound;
+				}
 			}
 		}
-		
 	CleanupStack::PopAndDestroy(tmpBuf);
 	
 	if(str.Length()>1)