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

Wrong format specifiers in kick/ban console command error paths #7993

Closed
JGRennison opened this issue Feb 9, 2020 · 1 comment
Closed

Wrong format specifiers in kick/ban console command error paths #7993

JGRennison opened this issue Feb 9, 2020 · 1 comment

Comments

@JGRennison
Copy link
Contributor

Version of OpenTTD

Since 805ecd3

Expected result

Correct format specifier used, no compiler warnings

Actual result

kick_message_length is declared as a size_t since 805ecd3, but format specifier %d is used.
PRINTF_SIZE should be used instead (or alternatively it could be changed back to an int with a suitable cast, I don't think there's much risk of overflow here).

/home/jgr/openttd/trunk/src/console_cmds.cpp: In function ‘bool ConKick(byte, char**)’:
/home/jgr/openttd/trunk/src/console_cmds.cpp:532:96: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
  532 |   IConsolePrintF(CC_ERROR, "ERROR: Maximum kick message length is 254 characters. You entered %d characters.", kick_message_length);
      |                                                                                               ~^               ~~~~~~~~~~~~~~~~~~~
      |                                                                                                |               |
      |                                                                                                int             size_t {aka long unsigned int}
      |                                                                                               %ld
/home/jgr/openttd/trunk/src/console_cmds.cpp: In function ‘bool ConBan(byte, char**)’:
/home/jgr/openttd/trunk/src/console_cmds.cpp:556:96: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
  556 |   IConsolePrintF(CC_ERROR, "ERROR: Maximum kick message length is 254 characters. You entered %d characters.", kick_message_length);
      |                                                                                               ~^               ~~~~~~~~~~~~~~~~~~~
      |                                                                                                |               |
      |                                                                                                int             size_t {aka long unsigned int}
      |                                                                                               %ld

Steps to reproduce

Compile 805ecd3 or later

LordAro added a commit to LordAro/OpenTTD that referenced this issue Feb 9, 2020
LordAro added a commit to LordAro/OpenTTD that referenced this issue Feb 9, 2020
@LordAro
Copy link
Member

LordAro commented Feb 9, 2020

I'd noticed this earlier. Fix is trivial enough :)

@LordAro LordAro closed this as completed in 8800225 Feb 9, 2020
LordAro added a commit to LordAro/OpenTTD that referenced this issue Feb 29, 2020
Berbe pushed a commit to Berbe/OpenTTD that referenced this issue Mar 6, 2020
Berbe pushed a commit to Berbe/OpenTTD that referenced this issue Mar 6, 2020
douiwby pushed a commit to douiwby/OpenTTD that referenced this issue Apr 16, 2020
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

No branches or pull requests

2 participants