fix small undefined behavior