[R-package] use safer pattern for error formatting (fixes #6212) #6216
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #6212.
Resolves warning
-Wformat-security
raised with R-devel as of a few days ago andclang-15
: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.
LightGBM/build-cran-package.sh
Lines 140 to 143 in 2ee3ec8
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
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.