Fix read()'s return value when length is too small