TMP: fix readN & writeN to not encourage UB