wmdrm/wmdrmengine/asf/src/asf.cpp
changeset 60 916cdf3599c4
parent 0 95b198f216e5
--- a/wmdrm/wmdrmengine/asf/src/asf.cpp	Thu Jul 08 20:21:37 2010 +0300
+++ b/wmdrm/wmdrmengine/asf/src/asf.cpp	Thu Jul 22 14:33:19 2010 +0300
@@ -86,6 +86,11 @@
     TInt aOffset,
     TInt aLength );
 
+LOCAL_C HBufC16* HBuf16IgnoreNullL(
+    const TDesC8& aBlock,
+    TInt aOffset,
+    TInt aLength );
+
 LOCAL_C TUint32 ReadUint64FromBlockL( const TDesC8& aBlock, TInt aOffset )
     {
     if ( aBlock.Length() <= ( aOffset + 3 ) )
@@ -140,6 +145,33 @@
 	return buffer;
     }
 
+LOCAL_C HBufC16* HBuf16IgnoreNullL(
+    const TDesC8& aBlock,
+    TInt aOffset,
+    TInt aLength )
+    {
+    if ( aBlock.Length() < ( aOffset + aLength ) )
+        {
+        User::Leave( KErrArgument );
+        }
+    HBufC16* buffer( HBufC16::NewL( aLength / 2 + 1 ) );
+    TPtr ptr( buffer->Des() );
+    
+    for ( TInt i( 0 ) ; i < aLength; i+=2 )
+        {
+        ptr.Append( aBlock[aOffset + i] );
+        }
+    
+    TInt dLength = ptr.Length();
+    
+    if ( dLength != 0 && ptr[dLength - 1] == '\0' )
+        {
+        ptr.SetLength( dLength - 1 );
+        }
+    
+    return buffer;
+    }
+
 // ============================ MEMBER FUNCTIONS ===============================
 
 // -----------------------------------------------------------------------------
@@ -582,15 +614,19 @@
         User::Leave( KErrOverflow );
         }
 
-    iTitle = HBuf16FromBlockL( *iHeaderData, offset, iTitleLength );
+    iTitle = HBuf16IgnoreNullL( *iHeaderData, offset, iTitleLength );
     offset += iTitleLength;
-    iAuthor = HBuf16FromBlockL( *iHeaderData, offset, iAuthorLength );
+    
+    iAuthor = HBuf16IgnoreNullL( *iHeaderData, offset, iAuthorLength );
     offset += iAuthorLength;
-    iCopyright = HBuf16FromBlockL( *iHeaderData, offset, iCopyrightLength );
+    
+    iCopyright = HBuf16IgnoreNullL( *iHeaderData, offset, iCopyrightLength );
     offset += iCopyrightLength;
-    iDescription = HBuf16FromBlockL( *iHeaderData, offset, iDescriptionLength );
+    
+    iDescription = HBuf16IgnoreNullL( *iHeaderData, offset, iDescriptionLength );
     offset += iDescriptionLength;
-    iRating = HBuf16FromBlockL( *iHeaderData, offset, iRatingLength );
+    
+    iRating = HBuf16IgnoreNullL( *iHeaderData, offset, iRatingLength );
     offset += iRatingLength;
     }