Fix buffer checks for snprintf
Re-arrange code to quiet Coverity
Set g.  CID #1206507
Limit lengths of strings in packets.  Fixes CID #1206505
Simplify logic to open the detail file.  Fixes CID #720458