SI-7319 A modest refactoring of error/warning buffer handling.

Much, much more is required, but that should be targetted against
master. This change is limited to cleaning up obvious bugs while
avoiding major behavioural changes.