[Chapel Merge] fix I/O bug in _ftoa_core to solve issue 17170

Branch: refs/heads/master
Revision: caa34d7
Author: mppf
Log Message:

Merge pull request #17171 from mppf/fix-ftoa-core-bug

fix I/O bug in _ftoa_core to solve issue 17170

Resolves #17170

PR #3870 added some code to _ftoa_core that examines and updates the
output. But, it did not correctly handle the case that not all of the
output was present (in particular when there was not enough room left in
the current buffer) or when snprintf returned an error. This PR updates
the existing conditional to check that the snprintf was successful.
(Note that if snprintf returned buf_sz that would actually indicate
not enough room in the output because snprintf would store the trailing
\0 byte instead of the expected output as the last character).

Adds a test that reproduces the error so we can avoid it in the future.

  • [x] full local testing

Reviewed by @ben-albrecht - thanks!

Modified Files:
A test/io/ferguson/issue-17170.chpl
A test/io/ferguson/issue-17170.good
A test/io/ferguson/issue-17170.prediff
M runtime/src/qio/qio_formatted.c

Compare: Comparing 8e03c9e25772...caa34d7aea94 · chapel-lang/chapel · GitHub