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

Fix: do not use lengthof() for non C-style arrays #12432

Merged
merged 2 commits into from
Apr 6, 2024

Conversation

rubidium42
Copy link
Contributor

Motivation / Problem

Using lengthof of C++-containers is all kinds of bad.

Description

Replace the cases where lengthof was used incorrectly with a simple substitute. It's not the proper-proper fix, but that requires migrating more to proper C++-containers and that makes backporting this a lot harder.

Replace lengthof with a variant that simply causes compilation failures when a non C-style array is passed. It is the way the locations with problems were found.

Limitations

Going fully C++ containers is the better way, but baby steps.
This is just trying to do the minimum to have something that can be backported easily.

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR touches english.txt or translations? Check the guidelines
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, game_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

@rubidium42 rubidium42 added the backport requested This PR should be backport to current release (RC / stable) label Apr 5, 2024
Copy link
Member

@PeterN PeterN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprisingly few, tbh.

@rubidium42 rubidium42 merged commit 97bea56 into OpenTTD:master Apr 6, 2024
15 checks passed
@rubidium42 rubidium42 deleted the lengthof branch April 6, 2024 05:21
@glx22 glx22 added backported This PR is backported to a current release (RC / stable) and removed backport requested This PR should be backport to current release (RC / stable) labels Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported This PR is backported to a current release (RC / stable)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants