dwatteau / scummtr

Fan translation tools for SCUMM engine games
MIT License
23 stars 4 forks source link

[Build warning] -Wstringop-overflow: writing 1 byte into a region of size 0 in _getOptions() #8

Closed dwatteau closed 3 years ago

dwatteau commented 3 years ago

Seen with g++ 10.2.0, when building in release mode with -O2.

ScummRp/scummrp.cpp: In static member function 'static void ScummRp::_getOptions(int, const char**, const ScummRp::Parameter*)':
ScummRp/scummrp.cpp:528:57: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
  528 |   for (j = 0; pendingParams[j] != 0; pendingParams[j++] = 0)
      |                                      ~~~~~~~~~~~~~~~~~~~^~~
ScummRp/scummrp.cpp:523:7: note: at offset 17 to object 'pendingParams' with size 17 declared here
  523 |  char pendingParams[MAX_PARAMS + 1];
      |       ^~~~~~~~~~~~~

ScummTr/scummtr.cpp: In static member function 'static void ScummTr::_getOptions(int, const char**, const ScummRp::Parameter*)':
ScummTr/scummtr.cpp:464:57: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
  464 |   for (j = 0; pendingParams[j] != 0; pendingParams[j++] = 0)
      |                                      ~~~~~~~~~~~~~~~~~~~^~~
ScummTr/scummtr.cpp:459:7: note: at offset 17 to object 'pendingParams' with size 17 declared here
  459 |  char pendingParams[MAX_PARAMS + 1];
      |       ^~~~~~~~~~~~~

This could be a false positive, though. I'd need to check.

dwatteau commented 3 years ago

Looks like this is a GCC 10 bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98561

and that it only happens when building with -O3. I'll disable -O3 in release mode, it doesn't bring anything and it's known to sometimes be buggy anyway.