diag_vlen is 32bit here - is that comparison sane? I've seen this pattern a couple of times (when you changed types to int64 for the variable in the loop.