8000 Adds test harness for itoa function; fixes bugs in that function by boredzo · Pull Request #32 · haywire/haywire · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Adds test harness for itoa function; fixes bugs in that function #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

boredzo
Copy link
@boredzo boredzo commented Jul 7, 2013

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.

boredzo added 2 commits July 7, 2013 13:08
itoa now uses all 32 characters of its buffer (one has been added to fit the null terminator in such cases), and takes unsigned rather than signed ints—since it's never used to represent negative numbers, and negative bases don't make any (at least practical) sense.

This fixes the previously-broken case tested by the harness from the previous commit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0