Adds test harness for itoa function; fixes bugs in that function #32
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
itoa accepted negative numbers, but didn't generate negative representations. It also did not correctly handle numbers that used all of the characters in its buffer before the null terminator; i.e., negative numbers in at least binary.
This patch introduces a small test program that tests a couple of cases (one simple case, one extreme case), and fixes the bugs that one of the test cases confirmed.
With this patch, itoa expects unsigned integers for both value and base, making explicit that it should only be expected to represent non-negative numbers, and it correctly represents even those numbers that are a full 32 bits long in binary.
This patch uses GCC and Clang's binary numeric literal syntax, which is non-standard; if you wish to make the test program portable to other compilers, you'll need to replace that literal with a decimal or hexadecimal literal.