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

Codechange: Use __attribute__ access none to silence GCC 11 -Wmaybe-uninitialized warnings #9124

Merged
merged 1 commit into from Apr 28, 2021

Conversation

@Milek7
Copy link
Contributor

@Milek7 Milek7 commented Apr 27, 2021

Motivation / Problem

GCC11 generates warnings like these:

/home/milek7/ottd3/src/settings.cpp: In function ‘GRFConfig* LoadGRFPresetFromConfig(const char*)’:
/home/milek7/ottd3/src/settings.cpp:1859:17: warning: ‘<unknown>’ may be used uninitialized [-Wmaybe-uninitialized]
 1859 |         seprintf(section, section + len - 1, "preset-%s", config_name);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/milek7/ottd3/src/currency.h:14,
                 from /home/milek7/ottd3/src/settings.cpp:26:
/home/milek7/ottd3/src/string_func.h:37:11: note: by argument 2 of type ‘const char*’ to ‘int seprintf(char*, const char*, const char*, ...)’ declared here
   37 | int CDECL seprintf(char *str, const char *last, const char *format, ...) WARN_FORMAT(3, 4);
      |           ^~~~~~~~
/home/milek7/ottd3/src/settings.cpp: In function ‘void SaveGRFPresetToConfig(const char*, GRFConfig*)’:
/home/milek7/ottd3/src/settings.cpp:1878:17: warning: ‘<unknown>’ may be used uninitialized [-Wmaybe-uninitialized]
 1878 |         seprintf(section, section + len - 1, "preset-%s", config_name);

Description

Use __attribute__ access none to specify that arguments pointing at buffer end are never dereferenced.

Limitations

__has_attribute cannot be utilized because none is recently added option to access attribute.

Pre-release GCC11.0 builds will also generate this warning, but it cannot be included in version check as early GCC11.0 builds didn't know about none option. (thus this PR checks for >11.1 release)

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
@LordAro
Copy link
Member

@LordAro LordAro commented Apr 27, 2021

See also #8522 and following revert #8526

Copy link
Member

@LordAro LordAro left a comment

Seems fine now :)

@LordAro LordAro merged commit 8e9eca6 into OpenTTD:master Apr 28, 2021
12 checks passed
LordAro added a commit to LordAro/OpenTTD that referenced this issue May 1, 2021
LordAro added a commit to LordAro/OpenTTD that referenced this issue May 1, 2021
LordAro added a commit to LordAro/OpenTTD that referenced this issue May 2, 2021
LordAro added a commit to LordAro/OpenTTD that referenced this issue May 2, 2021
LordAro added a commit that referenced this issue May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants