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 calloc-transposed-args with prism #9810

Merged
merged 1 commit into from
May 27, 2024
Merged

Conversation

JamieMagee
Copy link
Contributor

@JamieMagee JamieMagee commented May 23, 2024

GCC 14 was release on 7th May1. It introduced a new warning -Wcalloc-transposed-args2 designd to raise a warning when the arguments to calloc were given in the wrong order.

Unfortunately, prism version 0.24.0 made this mistake. Attempting to bundle install Dependabot gives the error:

src/diagnostic.c: In function ‘pm_diagnostic_list_append’:
src/diagnostic.c:328:69: error: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
  328 |     pm_diagnostic_t *diagnostic = (pm_diagnostic_t *) calloc(sizeof(pm_diagnostic_t), 1);
      |                                                                     ^~~~~~~~~~~~~~~
src/diagnostic.c:328:69: note: earlier argument should specify number of elements, later size of each element
src/diagnostic.c: In function ‘pm_diagnostic_list_append_format’:
src/diagnostic.c:359:69: error: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
  359 |     pm_diagnostic_t *diagnostic = (pm_diagnostic_t *) calloc(sizeof(pm_diagnostic_t), 1);
      |                                                                     ^~~~~~~~~~~~~~~
src/diagnostic.c:359:69: note: earlier argument should specify number of elements, later size of each element
cc1: all warnings being treated as errors

The issue was logged upstream in ruby/prism#2645, fixed in ruby/prism#2648, and released in https://github.com/ruby/prism/releases/tag/v0.25.0.

This change upgrades prism, by way of upgrading rbi, and resolves the compile error.

Footnotes

  1. https://gcc.gnu.org/gcc-14/

  2. https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wno-calloc-transposed-args

@JamieMagee JamieMagee requested a review from a team as a code owner May 23, 2024 05:36
@JamieMagee JamieMagee force-pushed the jamiemagee/prism-calloc branch 3 times, most recently from d225009 to a05e036 Compare May 24, 2024 21:53
GCC 14 was release on 7th May[^1]. It introduced a new warning `-Wno-calloc-transposed-args`[^2] designd to raise a warning when the arguments to `calloc` were given in the wrong order.

Unfortunately, `prism` version `0.24.0` made this mistake. Attempting to `bundle install` Dependabot gives the error:

<details>
<summary>Error details</summary>

```
src/diagnostic.c: In function ‘pm_diagnostic_list_append’:
src/diagnostic.c:328:69: error: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
  328 |     pm_diagnostic_t *diagnostic = (pm_diagnostic_t *) calloc(sizeof(pm_diagnostic_t), 1);
      |                                                                     ^~~~~~~~~~~~~~~
src/diagnostic.c:328:69: note: earlier argument should specify number of elements, later size of each element
src/diagnostic.c: In function ‘pm_diagnostic_list_append_format’:
src/diagnostic.c:359:69: error: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
  359 |     pm_diagnostic_t *diagnostic = (pm_diagnostic_t *) calloc(sizeof(pm_diagnostic_t), 1);
      |                                                                     ^~~~~~~~~~~~~~~
src/diagnostic.c:359:69: note: earlier argument should specify number of elements, later size of each element
cc1: all warnings being treated as errors
```

</details>

The issue was logged upstream in ruby/prism#2645, fixed in ruby/prism#2648, and released in https://github.com/ruby/prism/releases/tag/v0.25.0.

This change upgrades `prism`, by way of upgrading `rbi`, and resolves the compile error.

[^1]: https://gcc.gnu.org/gcc-14/
[^2]: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wno-calloc-transposed-args
@sachin-sandhu sachin-sandhu merged commit 7afe317 into main May 27, 2024
53 checks passed
@sachin-sandhu sachin-sandhu deleted the jamiemagee/prism-calloc branch May 27, 2024 15:47
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

Successfully merging this pull request may close these issues.

None yet

4 participants