8000 gcc 7 format-truncation errors · Issue #2423 · collectd/collectd · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
gcc 7 format-truncation errors #2423
Closed
Closed
@nwf

Description

@nwf
  • Version of collectd: HEAD (4380983)
  • Operating system / distribution: Debian Linux

When attempting to build with gcc (Debian 7.2.0-1) 7.2.0, I get several warnings-turned-errors about format-truncation:

  • In mcelog.c:
src/mcelog.c: In function ‘mcelog_dimm.isra.3’:
src/mcelog.c:127:48: error: ‘%s’ directive output may be truncated writing up to 127 bytes into a region of size between 0 and 127 [-Werror=format-truncation=]
     snprintf(dimm_name, sizeof(dimm_name), "%s_%s", rec->location,
                                                ^~
src/mcelog.c:127:5: note: ‘snprintf’ output between 2 and 256 bytes into a destination of size 128
     snprintf(dimm_name, sizeof(dimm_name), "%s_%s", rec->location,
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              rec->dimm_name);
              ~~~~~~~~~~~~~~~
src/mcelog.c: In function ‘poll_worker’:
src/mcelog.c:364:64: error: ‘%s’ directive output may be truncated writing up to 127 bytes into a region of size between 0 and 127 [-Werror=format-truncation=]
     snprintf(n.plugin_instance, sizeof(n.plugin_instance), "%s_%s",
                                                                ^~
              mr->location, mr->dimm_name);
                            ~~                                   
src/mcelog.c:364:5: note: ‘snprintf’ output between 2 and 256 bytes into a destination of size 128
     snprintf(n.plugin_instance, sizeof(n.plugin_instance), "%s_%s",
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              mr->location, mr->dimm_name);
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/mcelog.c:430:66: error: ‘%s’ directive output may be truncated writing up to 127 bytes into a region of size between 0 and 127 [-Werror=format-truncation=]
     snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s_%s",
                                                                  ^~
              mr->location, mr->dimm_name);
                            ~~                                     
src/mcelog.c:430:5: note: ‘snprintf’ output between 2 and 256 bytes into a destination of size 128
     snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s_%s",
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              mr->location, mr->dimm_name);
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/mcelog.c:438:40: error: ‘%s’ directive output may be truncated writing up to 127 bytes into a region of size 101 [-Werror=format-truncation=]
            "corrected_memory_errors_in_%s", mr->corrected_err_timed_period);
                                        ^~   ~~
src/mcelog.c:437:3: note: ‘snprintf’ output between 28 and 155 bytes into a destination of size 128
   snprintf(vl.type_instance, sizeof(vl.type_instance),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            "corrected_memory_errors_in_%s", mr->corrected_err_timed_period);
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/mcelog.c:448:42: error: ‘%s’ directive output may be truncated writing up to 127 bytes into a region of size 99 [-Werror=format-truncation=]
            "uncorrected_memory_errors_in_%s", mr->uncorrected_err_timed_period);
                                          ^~   ~~
src/mcelog.c:447:3: note: ‘snprintf’ output between 30 and 157 bytes into a destination of size 128
   snprintf(vl.type_instance, sizeof(vl.type_instance),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            "uncorrected_memory_errors_in_%s", mr->uncorrected_err_timed_period);
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
Makefile:5708: recipe for target 'src/mcelog.lo' failed

Some of these appear amenable to just increasing the target buffer size (ala commit 37b6652), but line 364, for example, targets a structure member, and I'm not comfortable making such a non-local change. :)

  • in utils_tail_match.c:
src/utils_tail_match.c: In function ‘latency_submit_match’:
src/utils_tail_match.c:122:64: error: ‘%.0f’ directive output may be truncated writing between 1 and 310 bytes into a region of size between 0 and 127 [-Werror=format-truncation=]
       snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%.0f",
                                                                ^~~~
src/utils_tail_match.c:122:7: note: ‘snprintf’ output between 3 and 439 bytes into a destination of size 128
       snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%.0f",
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                data->type_instance, data->latency_config.percentile[i]);
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/utils_tail_match.c:150:64: error: ‘%s’ directive output may be truncated writing up to 127 bytes into a region of size between 0 and 127 [-Werror=format-truncation=]
       snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%s-%g_%g",
                                                                ^~
src/utils_tail_match.c:150:60: note: assuming directive output of 12 bytes
       snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%s-%g_%g",
                                                            ^~~~~~~~~~~~~
src/utils_tail_match.c:150:60: note: assuming directive output of 12 bytes
src/utils_tail_match.c:150:7: note: ‘snprintf’ output between 6 and 284 bytes into a destination of size 128
       snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%s-%g_%g",
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                data->type, data->type_instance, lower_bound, upper_bound);
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/utils_tail_match.c:153:64: error: ‘%g’ directive output may be truncated writing between 1 and 13 bytes into a region of size between 0 and 127 [-Werror=format-truncation=]
       snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%g_%g",
                                                                ^~
src/utils_tail_match.c:153:60: note: assuming directive output of 12 bytes
       snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%g_%g",
                                                            ^~~~~~~~~~
src/utils_tail_match.c:153:60: note: assuming directive output of 12 bytes
src/utils_tail_match.c:153:7: note: ‘snprintf’ output between 5 and 156 bytes into a destination of size 128
       snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%g_%g",
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                data->type, lower_bound, upper_bound);
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

These, too, write into structure members.

  • in target_notification.c:
src/target_notification.c: In function ‘tn_invoke’:
src/target_notification.c:224:49: error: ‘%s’ directive output may be truncated writing up to 127 bytes into a region of size 123 [-Werror=format-truncation=]
     snprintf(template, sizeof(template), "%%{ds:%s}", ds->ds[i].name);
                                                 ^~
src/target_notification.c:224:5: note: ‘snprintf’ output between 7 and 134 bytes into a destination of size 128
     snprintf(template, sizeof(template), "%%{ds:%s}", ds->ds[i].name);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

Here, the warnings are silenced by using char template[DATA_MAX_NAME_LEN+6];.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0