Implement exporting a Pcmd to a file with the track and position range.
Fix a few things found by the Clang Static Analyzer.