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

[R-package] use safer pattern for error formatting (fixes #6212) #6216

Merged
merged 1 commit into from
Nov 30, 2023

Conversation

jameslamb
Copy link
Collaborator

@jameslamb jameslamb commented Nov 28, 2023

Fixes #6212.

Resolves warning -Wformat-security raised with R-devel as of a few days ago and clang-15:

lightgbm_R.cpp:159:3: warning: format string is not a string literal (potentially insecure) [-Wformat-security]

See #6212 (comment) for more details informing the changes in this PR.

Why not just suppress this warning?

CRAN has in the past not allowed compiler flags or pragmas in code that suppress warnings.

I couldn't find that stated explicitly in the CRAN policy (https://cran.r-project.org/web/packages/policies.html) or Writing R Extensions (https://cran.r-project.org/doc/manuals/R-exts.html), although there are some valid things there that note that warning-control flags can be compiler-specific and therefore add maintenance complexity to achieve portability. e.g. from https://cran.r-project.org/doc/manuals/R-exts.html#Portable-C-and-C_002b_002b-code

When writing a Makevars file for a package you intend to distribute, take care to ensure that it is not specific to your compiler: flags such as -O2 -Wall -pedantic (and all other -W flags: for the Oracle compilers these were used to pass arguments to compiler phases) are all specific to GCC (and compilers such as clang which aim to be options-compatible with it).

So unless there's some other performance, safety, or correctness issue I'm unaware of, I think the fix in this PR is a good approach to satisfying clang-15 and therefore the CRAN checks.

Notes for Reviewers

@shiyu1994 @guolinke @jmoralez this PR will unblock LightGBM's CI.

@david-cortes if you have other opinions on the approach I took here I'd welcome them.

@jameslamb jameslamb added the fix label Nov 28, 2023
@jameslamb jameslamb changed the title WIP: [R-package] use safer pattern for error formatting (fixes #6212) [R-package] use safer pattern for error formatting (fixes #6212) Nov 28, 2023
@jameslamb jameslamb marked this pull request as ready for review November 28, 2023 06:29
@jameslamb
Copy link
Collaborator Author

@guolinke @shiyu1994 sorry for the @, but could one of you please review this? It should be non-controversial and quick, and it fixes an issue that's blocking other PRs from being merged.

Thank you.

Copy link
Collaborator

@guolinke guolinke left a comment

Choose a reason for hiding this comment

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

LGTM

@jameslamb
Copy link
Collaborator Author

thanks @guolinke !

@jameslamb jameslamb merged commit 848e76c into master Nov 30, 2023
41 checks passed
@jameslamb jameslamb deleted the r/format-warnings branch November 30, 2023 04:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[R-package] warning on R-devel with clang 15: 'format string is not a string literal'
2 participants