isledecomp / SIEdit

Tools for working with SI files.
GNU General Public License v3.0
135 stars 9 forks source link

Make warning: potentially uninitialized variable in lib/file.cpp #8

Closed Techwizz-somboo closed 1 year ago

Techwizz-somboo commented 1 year ago
/home/arch/test/src/SIEdit/lib/file.cpp: In member function 'virtual void si::File::seek(si::FileBase::pos_t, si::FileBase::SeekMode)':
/home/arch/test/src/SIEdit/lib/file.cpp:132:26: error: 'd' may be used uninitialized [-Werror=maybe-uninitialized]
  132 |     FSTR(m_Handle)->seekp(p, d);
      |                          ^
/home/arch/test/src/SIEdit/lib/file.cpp:115:21: note: 'd' was declared here
  115 |   std::ios::seekdir d;
      |                     ^
cc1plus: all warnings being treated as errors
make[2]: *** [lib/CMakeFiles/libweaver.dir/build.make:90: lib/CMakeFiles/libweaver.dir/file.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:117: lib/CMakeFiles/libweaver.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
==> ERROR: A failure occurred in build().
    Aborting...

Since warnings are to be treated as errors by your CMake scripts, I'm posting this here.

This warning is thrown on Arch Linux with GCC 13.2.1.

archstrap $ gcc --version
gcc (GCC) 13.2.1 20230801

The warning isn't thrown on Alpine with GCC 12.2.1.

~ $ gcc --version
gcc (Alpine 12.2.1_git20220924-r10) 12.2.1 20220924

The solution is to initialize d before using it.

Opening a PR.