Skip to content

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

Merged
jameslamb merged 1 commit intomasterfrom
r/format-warnings
Nov 30, 2023
Merged

[R-package] use safer pattern for error formatting (fixes #6212)#6216
jameslamb merged 1 commit intomasterfrom
r/format-warnings

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 !

@github-actions
Copy link
Contributor

This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions bot removed the blocking label Dec 19, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

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