moved allocation of "diag" to after cmdline argument handling (possible also an error in other branches)