-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[ffi] Varargs should give an error on uint8, int8, uint16, int16 and float #56058
Comments
hey |
Hi @vaishnavi-2901! That's great! Please start with https://github.com/dart-lang/sdk/blob/main/CONTRIBUTING.md A PR for this issue will involve adding error messages both to the CFE (the compiler used when doing Some pointers to point you in the right direction:
It's probably easiest to
|
hey sir can i work on it ..? |
@vaishnavi-2901 are you still working on this? |
Dear respected sir let she work and let me also work on it. as I am beginning the open source contribution first you will check the request of both and then you will see what to do |
Hi @dcharkes , as you said clang just warn and promote Int8 Int16 (also Uint's) to 32bit data, But in dart side you are suggesting to throw error. Am not sure whether someone will report this or ask this, "Clang is allowing (just warning) but why dart is throwing error for varargs for 8bit, 16bit data" (am not familiar with ffi eco system, just wondering some program work (warn) when u compile natively (clang or gcc), but same program ends in error when runs by dart, is or will this bother someone ?) Sorry if this is too dumb. |
That has to do with the philosophy of C compilers: They warn and don't error on undefined behavior. (For sanity sake, we usually pass In Dart we have a slightly different approach. We want to prevent programs from compiling that will crash. Now on the For this specific bug. We saw undefined behavior leading to mangled enum and integer values and crashes. See the bug that is referenced in the top. |
I think this is a bit off topic, but do you have any idea why variadic dint allow < 4 byte data such as Because i wondered if its about the size then we can create custom data with any size we want using For ex: This code throw warning (eventually exit when executing this code, i compiled with gcc), short a = va_arg(arg, short) But if we have, struct Short {
short a;
};
...
struct a = va_arg(arg, struct Short)
.... The above don't have any warning and successfully executing (actually interpreting short) Am not sure is this valid, but am sure it is not affect anything here dart (thats why i mentioned it is off topic) Reason for this question is i just imagined C will reject any data type which is less than 4 byte (including struct) inside |
C just happily accepts things, even if it's undefined behavior. And the "best" part: the undefined behavior might "work" with some C compilers on some hardware, but not with other compilers. So you think your code is correct by testing it on one system and it not crashing, but it ends up crashing on another system. P.S. If you want to explore what various compilers do: https://godbolt.org/ You can play around with adding fields to the struct or changing the type and seeing how that changes the generated machine code. |
Passing 8 bit or 16 bit ints in varargs is undefined behavior.
Clang will alert us:
But we allow this in
dart:ffi
, leading to undefined behavior.We should consider adding an error message.
Discovered on:
The text was updated successfully, but these errors were encountered: