is: if ( size > 0 || rd.ready() ) should be: if ( size > pos || rd.ready() ) (or size > pos +1 ?) Artur