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

Possibly wrong constant values on any(target_os = "teeos", all(target_os = "linux", target_env = "uclibc", target_arch = "x86_64")) #3532

Open
ramhugger opened this issue Jan 9, 2024 · 0 comments
Labels
C-bug Category: bug

Comments

@ramhugger
Copy link

ramhugger commented Jan 9, 2024

Greetings,
I may have found a small set of constants whose values were included in libc as decimal literals while in fact they were written as octal literals in C. I believe this is the case because in C an integer literal that begins with a '0' is considered an octal literal, whereas in Rust the leading '0' is silently discarded.

I first noticed this while inspecting the value of O_NONBLOCK of another platform for a project of mine, and I noticed it had this declaration on Linux uClibc x86_64, which was inconsistent with all the other related values. This convinced me to investigate further, and I ran a RegExp against libc's codebase, which resulted in a small subset of constants (most are related to fcntl.h):
image

Before filing this issue, in order to be as sure and detailed as possible, I also went and gave a read to uClibc's Linux fcntl.h file, which uses in fact octal literals to declare the affected constants' values.

TL;DR

The constants listed above were likely copy-pasted from their respective headers and the subtle differences in integer literal rules from Rust and C lead to "wrong" values sneaking into the library...
unless I missed something and rustc is able to correctly interpret those literals as octals, which I unfortunately haven't been able to test on a Linux machine at the time of writing.

@ramhugger ramhugger added the C-bug Category: bug label Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

1 participant