The wrong end of `dst` is filled with zeros. Should be `memset(dst+srclen,0,maxlen-srclen);`.