fix hsmm write-off-end c++ bug