Only read buffer if it is non-null