JANITORIAL: DEVTOOLS: add missing special functions to file wrapper classes#7240
JANITORIAL: DEVTOOLS: add missing special functions to file wrapper classes#7240meekee7 wants to merge 5 commits intoscummvm:masterfrom
Conversation
|
I am not sure what actual (not theoretical) problem you are trying to solve here. Also, regardless of the reasoning, we still require following our Code Formatting Guidelines. |
|
@meekee7 any updates? |
|
I have applied clang-format to the relevant parts. |
|
The classes in question were not following the C++ rule of five. In create_xeen, For the other file handle wrapper classes, there are luckily no active hazards in their current usage. Nonetheless they are a code accident waiting to happen, just one change or refactoring away from creating a problem that is easily missed. |
|
We normally write and forget the tools. I am not great fan of writing code just for the sake of writing it. How was the |
|
I would suggest looking at PVS-Studio and Coverity; we have a significant amount of real issues there. If you could help here, you would be more than welcome. Here is our guide: https://wiki.scummvm.org/index.php?title=HOWTO-Static_Analysis_Tools |
The devtools contain many
stdio.hfile IO wrappers. Most of them lack special member functions declarations, making their implementation hazardous. The lack of a destructor means potential file handle leaks. The fact that copy and move are implicitly allowed means potential file handle duplication, double file handle closures and file handle use after closure.Missing destructors are added, copying and moving is forbidden for all
Fileclasses.In all cases, the
closeimplementation is reentrant-safe, meaning that a file closed manually can still be safely re-closed in the destructor.MemFilefrom create_xeen has a different situation. That class is used as a return value, meaning that it needs copy and move operations defined. Nonetheless the implicit functions were unsafe: C++11 does not guarantee the copy elision - that would require C++17. Thus there was unsafe copying and potential double-deletes masked by compiler optimizations.