Skip to content

Fix truncation errors for %d representation of int

Lukasz Kotasa requested to merge lk-int-truncation into devel

%d representation of int could be up to 10 or 11 characters (-2147483648 : 2147483647)

Fixes errors with broadcom compiler:

  ubus.c:1053:50: error: '%d' directive output may be truncated writing between 1 and 10 bytes into a region of size 3 [-Werror=format-truncation=]
 1053 |   snprintf(uciSection, sizeof(uciSection), "%s.%s%d", uciStrConfig, uciStrLineSect, line);
      |                                                  ^~
ubus.c:1053:44: note: directive argument in the range [0, 2147483647]
 1053 |   snprintf(uciSection, sizeof(uciSection), "%s.%s%d", uciStrConfig, uciStrLineSect, line);
      |                                            ^~~~~~~~~
ubus.c:1053:3: note: 'snprintf' output between 20 and 29 bytes into a destination of size 21
 1053 |   snprintf(uciSection, sizeof(uciSection), "%s.%s%d", uciStrConfig, uciStrLineSect, line);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ubus.c: In function 'config_init':
ubus.c:1123:47: error: '%d' directive output may be truncated writing between 1 and 10 bytes into a region of size 5 [-Werror=format-truncation=]
 1123 |   snprintf(uciSection, sizeof(uciSection), "%s%d", uciStrLineSect, line);
      |                                               ^~
ubus.c:1123:44: note: directive argument in the range [0, 2147483647]
 1123 |   snprintf(uciSection, sizeof(uciSection), "%s%d", uciStrLineSect, line);
      |                                            ^~~~~~
ubus.c:1123:3: note: 'snprintf' output between 11 and 20 bytes into a destination of size 14
 1123 |   snprintf(uciSection, sizeof(uciSection), "%s%d", uciStrLineSect, line);
Edited by Lukasz Kotasa

Merge request reports