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

BUILD: Reduce GCC warnings #1471

Closed
wants to merge 5 commits into from

Conversation

eriktorbjorn
Copy link
Member

This is not intended for immediate merge, but as a starting point for further discussion. ScummVM currently produces a lot of warnings when compiling with GCC 8. Possibly earlier versions as well. It would be good to silence the unnecessary compiler warnings, because the real warnings can easily be missed in the noise.

Most of the warnings, at the time I forked, were on the form "void* memset(void*, int, size_t)’ clearing an object of non-trivial type ‘...’; use assignment or value-initialization instead [-Wclass-memaccess]", so that's what I've focused on. The main method I've used is adding reset() methods to a number of classes and calling that instead. Is that a good approach? It seems a bit error-prone, since the method has to be updated if further members are added to the class or struct. And of course, I may have accidentally missed some as well.

There are still a couple of warnings remaining. Some of them looked non-trivial, and some were about memcpy() instead of memset(). In some cases, I didn't feel comfortable messing with that particular part of the code at the time.


void reset() {
button = 0;
pos.x = pos.y = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to use the default ctor here? What if the class gets more parameters in the future. You might end up with garbage values in that case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed the initialization of Mouse and AgiGame to what I think you meant. I did revert some such changes I had made before even committing them, but I missed those.

memset(&dirView[i], 0, sizeof(struct AgiDir));
memset(&dirSound[i], 0, sizeof(struct AgiDir));

pictures[i].flen = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same (default ctor) is true here. It is imo safer to let the classes define which members must be reset.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure yet. AgiDir gets cleared outside of the engine constructor in some cases, and I haven't checked if that still only happens on startup. I probably won't have the time to look any further today.

@digitall
Copy link
Member

digitall commented Jan 1, 2019

@eriktorbjorn : Thanks for looking at this. One point, can we rebase this to squash and then split this into a commit for each engine (and backend) prior to merge please?

Torbjörn Andersson added 5 commits January 5, 2019 20:09
Recent GCC versions complain if you memset() a class or struct that
contain non-POD data types. Get around that by either initializing
the object when created, or by adding a reset() method.
Recent GCC versions complain if you memset() a class or struct that
contain non-POD data types. Get around that by either initializing
the object when created, or by adding a reset() method.
Recent GCC versions complain if you memset() a class or struct that
contain non-POD data types. Get around that by either initializing
the object when created, or by adding a reset() method.
Recent GCC versions complain if you memset() a class or struct that
contain non-POD data types. Get around that by either initializing
the object when created, or by adding a reset() method.
Recent GCC versions complain if you memset() a class or struct that
contain non-POD data types. Get around that by either initializing
the object when created, or by adding a reset() method.
@bluegr
Copy link
Member

bluegr commented Jan 13, 2019

Looks good! +1 from me

@Mataniko Mataniko changed the title Gcc warnings BUILD: Reduce GCC warnings Feb 28, 2019
@bluegr
Copy link
Member

bluegr commented Mar 4, 2019

Any news on this? Are there any further actions to be taken? If not, we can merge this

@digitall
Copy link
Member

The commits with fixes to BACKENDS, FULLPIPE and AGOS look correct and reasonably trivial... The SCUMM and AGI engine changes are slightly more involved and probably should be reviewed in detail, including the AGI change maybe needing further changes as per @eriktorbjorn 's comment.

@albertvaka
Copy link

I'm an outsider here, but it looks to me like memset is less error-prone than a reset function (you will never miss fields to reset), plus it's probably faster (unless the compiler is really smart).

@sev-
Copy link
Member

sev- commented Mar 14, 2019

It all makes sense to me. Even with the reset() method. It is safer like this than the memset(), and we have Coverity for spotting uninitialized field.

@lotharsm
Copy link
Member

lotharsm commented Apr 3, 2019

Any objections against merging this?

@bluegr
Copy link
Member

bluegr commented Jul 14, 2019

The commits for SCUMM, AGOS, FULLPIPE and BACKENDS were quite straightforward, so I went ahead and merged them separately.

The commit for AGI would need more work concerning the AgiDir structures

@bluegr
Copy link
Member

bluegr commented Aug 26, 2019

The fixes for AGI have been fixed by separate commits, including 482f835 and 50c5177. Thus, this can be closed now

@bluegr bluegr closed this Aug 26, 2019
ccawley2011 pushed a commit to ccawley2011/scummvm that referenced this pull request Oct 10, 2020
@eriktorbjorn eriktorbjorn deleted the gcc-warnings branch February 11, 2022 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants