refactoring: npos_minus1
fix warning: unintentional integer overflow
use LENOF
fix warning: out-of-bounds write
fix warning: out-of-bounds write