Welcome to the Builder Academy

Question New GCC 7 Warnings

More
10 Jan 2020 11:57 #8471 by Rumble
New GCC 7 Warnings was created by Rumble
With the upgrade of the server we now have GCC 8.2.1 (thanks Opie) and some new warnings (thanks Redhat). I'm surprised no one has posted about them yet. Below are a few examples.
Code:
shop.c: In function ‘shop_keeper’: shop.c:802:48: warning: ‘%s’ directive output may be truncated writing up to 511 bytes into a region of size 503 [-Wformat-truncation=] snprintf(tempbuf, sizeof(tempbuf), "$n sells %s.", tempstr); ^~ ~~~~~~~ shop.c:802:3: note: ‘snprintf’ output between 11 and 522 bytes into a destination of size 512 snprintf(tempbuf, sizeof(tempbuf), "$n sells %s.", tempstr); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ shop.c:627:47: warning: ‘%s’ directive output may be truncated writing up to 511 bytes into a region of size 504 [-Wformat-truncation=] snprintf(tempbuf, sizeof(tempbuf), "$n buys %s.", tempstr); ^~ ~~~~~~~ shop.c:627:3: note: ‘snprintf’ output between 10 and 521 bytes into a destination of size 512 snprintf(tempbuf, sizeof(tempbuf), "$n buys %s.", tempstr); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ shop.c:627:47: warning: ‘%s’ directive output may be truncated writing up to 511 bytes into a region of size 504 [-Wformat-truncation=] snprintf(tempbuf, sizeof(tempbuf), "$n buys %s.", tempstr); ^~ ~~~~~~~ shop.c:627:3: note: ‘snprintf’ output between 10 and 521 bytes into a destination of size 512 snprintf(tempbuf, sizeof(tempbuf), "$n buys %s.", tempstr); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ shop.c:627:47: warning: ‘%s’ directive output may be truncated writing up to 511 bytes into a region of size 504 [-Wformat-truncation=] snprintf(tempbuf, sizeof(tempbuf), "$n buys %s.", tempstr); ^~ ~~~~~~~
These are warnings, not bugs and is expected behavior. The only result is snprintf truncating the text. Redhat explains their valid reasoning here.

The solution would be to define a larger temp buf size as required. But I'm not sure it is worth it.

Warnings can be hidden with Makefile change
MYFLAGS = -Wall
to
MYFLAGS = -Wall -Wno-format-truncation

Appreciate everyone's thoughts or if someone has already tackled this.

Rumble
The Builder Academy
tbamud.com 9091
rumble@tbamud.com

Please Log in or Create an account to join the conversation.

More
10 Jan 2020 20:23 #8472 by thomas
Replied by thomas on topic New GCC 7 Warnings
I think the correct fix for those is to make the tempstr 15 chars shorter.

I'll try running a build and see how much trouble they are.

Please Log in or Create an account to join the conversation.

More
11 Jan 2020 00:15 #8473 by thomas
Replied by thomas on topic New GCC 7 Warnings
Some of them were quite bad. I've made a PR with fixes. github.com/tbamud/tbamud/pull/74

Please Log in or Create an account to join the conversation.

More
11 Jan 2020 00:47 #8474 by Rumble
Replied by Rumble on topic New GCC 7 Warnings
Thanks Thomas, I plan to put together the 2020 release next week. Appreciate the help. Thanks for Merging Wyld.

Rumble
The Builder Academy
tbamud.com 9091
rumble@tbamud.com

Please Log in or Create an account to join the conversation.

Time to create page: 0.271 seconds