Skip to content
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

Undefined behavior in base64.h due to storing EOF in char type #2254

Closed
hcho3 opened this issue Dec 7, 2018 · 1 comment
Closed

Undefined behavior in base64.h due to storing EOF in char type #2254

hcho3 opened this issue Dec 7, 2018 · 1 comment

Comments

@hcho3
Copy link
Contributor

hcho3 commented Dec 7, 2018

Related: dmlc/xgboost#3976.

Currently, base64 stream stores EOF in a char variable, which may cause undefined behavior for ARM targets.

Details. std::istream.get() and getchar() have return type int, not char, because both may return EOF, which is commonly -1. Storing EOF in a char results in undefined behavior. The char type is usually signed on x86 systems but unsigned on ARM systems (see http://blog.cdleary.com/2012/11/arm-chars-are-unsigned-by-default/), so the undefined behavior will only be apparent when compiled on ARM.

Aside. AWS has recently begun offering ARM-backed EC2 instances.

@hcho3
Copy link
Contributor Author

hcho3 commented Dec 7, 2018

#2255 should address this issue.

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

No branches or pull requests

1 participant