CRAS: metrics - fix snprintf return handling

This fixes an issue where snprintf was using the return value
incorrectly. It returns the length of the format string that would be
printed, not the amount the snprintf limit caused to be printed.

To fix that, ensure that the loop exits as soon as the buffer is
consumed or an error is returned.

Change-Id: I6c8af006f38ea4ce24f190eb4145674b9df34e0b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/2447235
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Reviewed-by: Yu-Hsuan Hsu <yuhsuan@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Yu-Hsuan Hsu <yuhsuan@chromium.org>
1 file changed