Index: branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 1073)
+++ branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 1075)
@@ -3709,4 +3709,15 @@
   }
 
+#if NECESSARY_LAYER_FLAG
+  // Default output layer set
+  // The value of NumLayersInIdList[ 0 ] is set equal to 1 and the value of LayerSetLayerIdList[ 0 ][ 0 ] is set equal to 0.
+  vps->setOutputLayerSetIdx(0, 0);
+
+  // The value of output_layer_flag[ 0 ][ 0 ] is inferred to be equal to 1.
+  vps->setOutputLayerFlag(0, 0, true);
+
+  vps->deriveNecessaryLayerFlag(0);
+#endif
+
   // The value of sub_layer_dpb_info_present_flag[ i ][ 0 ] for any possible value of i is inferred to be equal to 1
   // When not present, the value of sub_layer_dpb_info_present_flag[ i ][ j ] for j greater than 0 and any possible value of i, is inferred to be equal to be equal to 0.
Index: branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 1073)
+++ branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 1075)
@@ -2907,4 +2907,11 @@
     return; // Already checked
   }
+
+  if( params->getTargetLayerId() > vps->getMaxLayerId() )
+  {
+    printf( "Warning: specified target layerId %d is greater than max layerId %d. Target layerId is set equal to max layerId %d.\n", params->getTargetLayerId(), vps->getMaxLayerId(), vps->getMaxLayerId() );
+    params->setTargetLayerId( vps->getMaxLayerId() );
+  }
+
   if( params->getTargetOutputLayerSetIdx() == -1 )  // Output layer set index not specified
   {
@@ -3200,7 +3207,7 @@
   }
 
-  for (UInt layer = 0; layer <= MAX_VPS_LAYER_IDX_PLUS1 - 1; layer++)
-  {
-    m_ppcTDecTop[layer]->m_smallestLayerId = smallestLayerId;
+  for( UInt layerId = 0; layerId < MAX_VPS_LAYER_IDX_PLUS1; layerId++ )
+  {
+    m_ppcTDecTop[layerId]->m_smallestLayerId = smallestLayerId;
   }
 }
