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

xxd Code Generation is not compatible with C standard for large arrays #13876

Open
Kuratius opened this issue Jan 17, 2024 · 2 comments
Open
Labels
bug xxd for xxd and related

Comments

@Kuratius
Copy link
Contributor

Kuratius commented Jan 17, 2024

Steps to reproduce

The option -i is supposed to generate an array length variable as an int. The C standard only guarantees 16 bits for an int. An array greater than 2^16 entries should cause issues.

Expected behaviour

Generate a type that can hold the maximum array size for a platform, e.g. size_t

Version of Vim

I read the source code on the repo

Environment

Irrelevant

Logs and stack traces

No response

@chrisbra
Copy link
Member

PR was reverted in fa8c971

@Kuratius
Copy link
Contributor Author

Kuratius commented Jan 25, 2024

From what I understand, the PR was reverted because some projects include the standard headers that have size_t after including the generated code from xxd -i, or don't include them at all, although I still don't know any examples of such projects.

So a solution needs to be implemented when xxd/vim decides to make a breaking change, the header needs to be included, or there needs to be fully dynamic type generation.

I'm not sure if there are examples where using dynamic type generation can still fail, but I suppose this depends on what calculations are done with the array size.

I'm sure it's possible to come up with pathological examples like https://mohitmv.github.io/blog/Shocking-Undefined-Behaviour-In-Action/ example1, but those might not necessarily be things that a normal person would do with an array size variable. It might happen when a type is not promoted appropriately, like if printing the size of an array in bytes whose individual entries are very large, assuming someone doesn't use sizeof() for this.

Implementing dynamic type generation would ideally also fix #13887 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug xxd for xxd and related
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants