-
Notifications
You must be signed in to change notification settings - Fork 16
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
stdlib: improve string to integer conversion functions #381
Conversation
c -= 'a' - 10; | ||
else | ||
} | ||
else { | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errno
should be set to EINVAL
if no conversion could be performed. This is an optional error condition, so I'm not 100% sure it will be useful in portable applications, but maybe it is worth including.
I have noticed that strtoul.c and strtoull.c still differ and are not unified/commonized completely and that's why EINVAL
is not set - is this intended (for now) to avoid a large refactor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked with glibc and it doesn't set errno
to EINVAL
if no conversion can be performed - so perhaps it won't be very useful, but I added it.
Making code for strtol
and strtoll
common would be tricky, because (at least on 32-bit platforms) they use different arithmetic types for intermediate results. If we used unsigned long long
for both of them, it would reduce performance if 32-bit conversion is requested. Although perhaps the impact wouldn't be large, because only addition and multiplication is used.
7473681
to
db1a1c2
Compare
Add setting of errno on underflow, overflow and wrong base. Unify common code between strtoll and strtoull. Make code MISRA compliant. JIRA: RTOS-869
Correct return value on signed long int overflow/underflow. Correct handling of "0x" prefix not followed by a hex digit. JIRA: RTOS-869
db1a1c2
to
e2d34ae
Compare
Add errno setting in
strto{u}ll
, fix minor bugs instrto{u}l
. Details in commit messages.Motivation and Context
Closes phoenix-rtos/phoenix-rtos-project#543
Types of changes
How Has This Been Tested?
Checklist:
Special treatment