Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silence a format truncation warning #15857

Merged
merged 1 commit into from
Nov 2, 2023

Conversation

zoltanvb
Copy link
Contributor

@zoltanvb zoltanvb commented Nov 1, 2023

Description

This line generates a warning during compilation:

menu/menu_displaylist.c:11925:46: warning: '%d' directive output may be truncated writing between 1 and 3 bytes into a region of size 2 [-Wformat-truncation=]
11925 |                                        "Mode %d", toc->track[i].mode);
      |                                              ^~
menu/menu_displaylist.c:11925:40: note: directive argument in the range [0, 255]
11925 |                                        "Mode %d", toc->track[i].mode);
      |                                        ^~~~~~~~~
In file included from /usr/include/stdio.h:936,
                 from ./libretro-common/include/file/file_path.h:26,
                 from menu/menu_displaylist.c:27:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:64:10: note: '__builtin___snprintf_chk' output between 7 and 9 bytes into a destination of size 7
   64 |   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   65 |        __bos (__s), __fmt, __va_arg_pack ());
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Since the value of the track mode should be either 1 or 2, a modulo 10 should not limit the displayed value, and it removes the warning.

This line generates a warning during compilation:

menu/menu_displaylist.c:11925:46: warning: '%d' directive output may be truncated writing between 1 and 3 bytes into a region of size 2 [-Wformat-truncation=]
11925 |                                        "Mode %d", toc->track[i].mode);
      |                                              ^~
menu/menu_displaylist.c:11925:40: note: directive argument in the range [0, 255]
11925 |                                        "Mode %d", toc->track[i].mode);
      |                                        ^~~~~~~~~
In file included from /usr/include/stdio.h:936,
                 from ./libretro-common/include/file/file_path.h:26,
                 from menu/menu_displaylist.c:27:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:64:10: note: '__builtin___snprintf_chk' output between 7 and 9 bytes into a destination of size 7
   64 |   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   65 |        __bos (__s), __fmt, __va_arg_pack ());
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Since the value of the track mode should be either 1 or 2, a modulo 10 should not limit the displayed value, and it removes the warning.
@LibretroAdmin LibretroAdmin merged commit 636a6e9 into libretro:master Nov 2, 2023
22 checks passed
JoeOsborn pushed a commit to JoeOsborn/RetroArch that referenced this pull request Nov 2, 2023
This line generates a warning during compilation:

menu/menu_displaylist.c:11925:46: warning: '%d' directive output may be truncated writing between 1 and 3 bytes into a region of size 2 [-Wformat-truncation=]
11925 |                                        "Mode %d", toc->track[i].mode);
      |                                              ^~
menu/menu_displaylist.c:11925:40: note: directive argument in the range [0, 255]
11925 |                                        "Mode %d", toc->track[i].mode);
      |                                        ^~~~~~~~~
In file included from /usr/include/stdio.h:936,
                 from ./libretro-common/include/file/file_path.h:26,
                 from menu/menu_displaylist.c:27:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:64:10: note: '__builtin___snprintf_chk' output between 7 and 9 bytes into a destination of size 7
   64 |   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   65 |        __bos (__s), __fmt, __va_arg_pack ());
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Since the value of the track mode should be either 1 or 2, a modulo 10 should not limit the displayed value, and it removes the warning.
@zoltanvb zoltanvb deleted the silence_format_warning branch November 11, 2023 09:44
Sunderland93 pushed a commit to Sunderland93/RetroArch that referenced this pull request Dec 26, 2024
This line generates a warning during compilation:

menu/menu_displaylist.c:11925:46: warning: '%d' directive output may be truncated writing between 1 and 3 bytes into a region of size 2 [-Wformat-truncation=]
11925 |                                        "Mode %d", toc->track[i].mode);
      |                                              ^~
menu/menu_displaylist.c:11925:40: note: directive argument in the range [0, 255]
11925 |                                        "Mode %d", toc->track[i].mode);
      |                                        ^~~~~~~~~
In file included from /usr/include/stdio.h:936,
                 from ./libretro-common/include/file/file_path.h:26,
                 from menu/menu_displaylist.c:27:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:64:10: note: '__builtin___snprintf_chk' output between 7 and 9 bytes into a destination of size 7
   64 |   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   65 |        __bos (__s), __fmt, __va_arg_pack ());
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Since the value of the track mode should be either 1 or 2, a modulo 10 should not limit the displayed value, and it removes the warning.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants