pcsx-redux icon indicating copy to clipboard operation
pcsx-redux copied to clipboard

Fix compilation warnings

Open TotalCaesar659 opened this issue 5 years ago • 5 comments

src/core/misc.cc: In function ‘bool CheckCdrom()’:
src/core/misc.cc:311:44: warning: format ‘%s’ expects argument of type ‘char*’, but argument 3 has type ‘const char8_t*’ [-Wformat=]
  311 |         sprintf(mcd1path, "memcards/games/%s-%02d.mcd",
      |                                           ~^
      |                                            |
      |                                            char*
      |                                           %hhn
  312 |                 PCSX::g_emulator->settings.get<PCSX::Emulator::SettingPsxExe>().string().c_str(), 1);
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                                               |
      |                                                                                               const char8_t*
src/core/misc.cc:313:44: warning: format ‘%s’ expects argument of type ‘char*’, but argument 3 has type ‘const char8_t*’ [-Wformat=]
  313 |         sprintf(mcd2path, "memcards/games/%s-%02d.mcd",
      |                                           ~^
      |                                            |
      |                                            char*
      |                                           %hhn
  314 |                 PCSX::g_emulator->settings.get<PCSX::Emulator::SettingPsxExe>().string().c_str(), 2);
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                                               |
      |                                                                                               const char8_t*
src/core/misc.cc: In function ‘void LoadLibPS()’:
src/core/misc.cc:356:20: warning: format ‘%s’ expects argument of type ‘char*’, but argument 3 has type ‘const char8_t*’ [-Wformat=]
  356 |     sprintf(buf, "%s/libps.exe",
      |                   ~^
      |                    |
      |                    char*
      |                   %hhn
  357 |             PCSX::g_emulator->settings.get<PCSX::Emulator::SettingBios>().value.parent_path().u8string().c_str());
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                                                               |
      |                                                                                                               const char8_t*
...
src/core/cdriso.cc: In member function ‘int PCSX::CDRiso::LoadSBI(const char*)’:
src/core/cdriso.cc:1295:28: warning: format ‘%s’ expects argument of type ‘char*’, but argument 3 has type ‘const char8_t*’ [-Wformat=]
 1295 |         sprintf(sbifile, "%s%s", PCSX::g_emulator->settings.get<Emulator::SettingPpfDir>().string().c_str(), buffer);
      |                           ~^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                            |                                                                             |
      |                            char*                                                                         const char8_t*
      |                           %hhn

TotalCaesar659 avatar May 22 '20 20:05 TotalCaesar659

So unfortunately, hhn is a POSIX specific extension, and most likely won't work properly in a cross platform setting.

At this point, it might make more sense to start using fmt::format, like I've done in other locations of the code:

https://github.com/grumpycoders/pcsx-redux/blob/c3a4c4654409be2928704dbf43650e1b9190da99/src/gui/widgets/dwarf.cc#L40

https://fmt.dev/latest/index.html

nicolasnoble avatar May 23 '20 01:05 nicolasnoble

Codecov Report

Merging #213 into master will decrease coverage by 0.00%. The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #213      +/-   ##
=========================================
- Coverage    1.61%   1.61%   -0.01%     
=========================================
  Files         134     134              
  Lines       35564   35568       +4     
=========================================
  Hits          574     574              
- Misses      34990   34994       +4     
Impacted Files Coverage Δ
src/core/cdriso.cc 0.00% <0.00%> (ø)
src/core/misc.cc 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update c3a4c46...aa6795a. Read the comment docs.

codecov[bot] avatar May 23 '20 14:05 codecov[bot]

@nicolasnoble I tried to understand this fmt, but please, help))

TotalCaesar659 avatar May 23 '20 14:05 TotalCaesar659

Right, well, moving over to fmt::format isn't a small undertaking :-) A lot of various algorithms and memory management routines around these functions need to change drastically. This is something that can be done at a later time. There's still much to be done :)

nicolasnoble avatar May 24 '20 03:05 nicolasnoble

Yeah, we can save that for later.

TotalCaesar659 avatar May 24 '20 17:05 TotalCaesar659