Skip to content

-Wformat clang/gcc warnings #5768

Description

@jangorecki

New compilation warnings on CRAN
https://www.r-project.org/nosvn/R.check/r-devel-linux-x86_64-fedora-clang/data.table-00check.html
Same warnings, but less, on GCC

checking whether package ‘data.table’ can be installed ... [57s/138s] WARNING
Found the following significant warnings:
  assign.c:470:83: warning: format specifies type 'int' but the argument has type 'R_xlen_t' (aka 'long') [-Wformat]
  assign.c:518:22: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  assign.c:794:96: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]
  forder.c:107:30: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:121:19: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:255:27: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:270:23: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:272:21: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:283:18: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:284:23: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:304:25: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:322:17: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:340:14: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:404:3: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:426:7: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:428:7: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:430:7: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:443:5: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:445:5: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:447:5: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:453:7: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:455:7: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:459:5: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:462:5: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:465:5: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:467:5: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:495:5: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:511:9: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:553:7: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:599:11: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:706:8: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:720:47: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:725:57: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:1045:36: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:1154:15: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:1261:38: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:1265:57: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:1270:29: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:1302:7: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:1315:29: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:1332:7: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  forder.c:1366:9: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  fread.c:1888:54: warning: format specifies type 'int' but the argument has type 'int64_t' (aka 'long') [-Wformat]
  fsort.c:168:102: warning: format specifies type 'int' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
  fsort.c:245:49: warning: format specifies type 'int' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
  fsort.c:249:54: warning: format specifies type 'int' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
  fwrite.c:626:28: warning: format specifies type 'int' but the argument has type 'const void *' [-Wformat]
  fwrite.c:711:68: warning: format specifies type 'int' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
  fwrite.c:731:15: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  fwrite.c:746:64: warning: format specifies type 'int' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
  fwrite.c:814:10: warning: format specifies type 'int' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
  fwrite.c:825:10: warning: format specifies type 'int' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
  fwrite.c:915:21: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  gsumm.c:90:38: warning: format specifies type 'int' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
  gsumm.c:90:48: warning: format specifies type 'int' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
  gsumm.c:90:56: warning: format specifies type 'int' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
  gsumm.c:90:67: warning: format specifies type 'int' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
  gsumm.c:609:90: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]
  gsumm.c:612:93: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]
  gsumm.c:638:92: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]
  gsumm.c:1411:72: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]
  ijoin.c:323:89: warning: data argument not used by format string [-Wformat-extra-args]
  init.c:153:139: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]
  init.c:168:71: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]
  init.c:169:77: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]
  init.c:171:83: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]
  init.c:172:106: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]
  init.c:173:105: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]
  init.c:173:119: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]
  init.c:174:81: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]
  init.c:175:79: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]
  init.c:176:87: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]
  init.c:177:77: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]
  init.c:178:79: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]
  init.c:179:79: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]
  init.c:180:81: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]
  init.c:184:95: warning: format specifies type 'int' but the argument has type 'R_xlen_t' (aka 'long') [-Wformat]
  rbindlist.c:212:37: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  rbindlist.c:233:50: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  rbindlist.c:234:48: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  rbindlist.c:494:31: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
  reorder.c:17:115: warning: format specifies type 'int' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
  reorder.c:27:136: warning: format specifies type 'int' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
  snprintf.c:217:136: warning: format specifies type 'char *' but the argument has type 'int' [-Wformat]
  subset.c:270:26: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
See the [install log](https://www.r-project.org/nosvn/R.check/r-devel-linux-x86_64-fedora-clang/data.table-00install.html) for details.
used C compiler: ‘clang version 17.0.5’

Activity

  1. added this to the 1.14.10 milestone on Nov 26, 2023
  2. changed the title [-]Wformat clang warnings[/-] [+]-Wformat clang/gcc warnings[/+] on Nov 26, 2023
  3. MichaelChirico commented on Nov 26, 2023

    @MichaelChirico
    Member

    The -Wformat-security warnings look like a particular nuisance. Can we just suppress those?

    e.g.

    data.table/src/assign.c

    Lines 517 to 518 in abcfe06

    const char *ret = memrecycle(targetcol, rows, 0, targetlen, thisvalue, 0, -1, coln+1, CHAR(STRING_ELT(names, coln)));
    if (ret) warning(ret);

  4. MichaelChirico commented on Nov 26, 2023

    @MichaelChirico
    Member

    format specifies type 'int' but the argument has type 'R_xlen_t' (aka 'long')

    Anyone see what's the correct template for R_xlen_t? It is potentially platform-specific right? e.g. size_t is supposed to be %zu, not %lu (which might be implied by the 'aka unsigned long' part).

  5. MichaelChirico commented on Nov 27, 2023

    @MichaelChirico
    Member

    OK, I found this r-devel thread:

    https://stat.ethz.ch/pipermail/r-devel/2022-January/081410.html

    It looks like we should use %lld for R_xlen_t, I'll make the change in #5769 if anyone else can confirm I'm reading that correctly.

    Here's the commit Martin references there, it is not v. helpful per se r-devel/r-svn@91c3c9f

  6. MichaelChirico commented on Nov 27, 2023

    @MichaelChirico
    Member

    There are a few places where R is casting R_xlen_t to long long, I'll do that instead of (long) in #5769.

    https://github.com/search?q=repo%3Ar-devel%2Fr-svn+%25lld+R_xlen_t&type=code

  7. jangorecki commented on Nov 28, 2023

    @jangorecki
    MemberAuthor

    @MichaelChirico
    CRAN release procedure includes that

    # No use of long long, instead use int64_t. TODO
    # grep "long long" ./src/*.c
    

    it is commented out

  8. MichaelChirico commented on Nov 29, 2023

    @MichaelChirico
    Member

    Thank you (as ever!) @eddelbuettel for pointing out the simple workaround for the format-security warning: dump the string with printf("%s", buff) instead of printf(buff). are there performances implications for this? I haven't looked if any of our warnings come in performance-sensitive regions...

  9. eddelbuettel commented on Nov 29, 2023

    @eddelbuettel
    Contributor

    @MichaelChirico AFAIK to there are not. It is the official way to it for Rf_error() and Rf_warnings().

  10. modified the milestones: 1.14.10, 1.15.0 on Dec 1, 2023
  11. jangorecki commented on Dec 1, 2023

    @jangorecki
    MemberAuthor

    resolved on hotfix branch, still needs to be cherry picked to master, so I was not removing branches in those two PRs

  12. modified the milestones: 1.15.0, 1.14.10 on Dec 2, 2023
  13. added a commit that references this issue on Jan 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions