ralna / CUTEst

The Constrained and Unconstrained Testing Environment with safe threads (CUTEst) for optimization software
Other
83 stars 18 forks source link

Warning during the compilation of the new version of CUTEst #39

Closed amontoison closed 6 months ago

amontoison commented 6 months ago

@nimgould

worhp_main.c:102:55: warning: ‘%s’ directive output may be truncated writing up to 127 bytes into a region of size 112 [-Wformat-truncation=]
  102 |     snprintf(buffer, sizeof(buffer), "CUTEst problem: %s", cutest_problem);
      |                                                       ^~   ~~~~~~~~~~~~~~
In file included from /usr/include/stdio.h:894,
                 from worhp_main.c:20:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:71:10: note: ‘__builtin___snprintf_chk’ output between 17 and 144 bytes into a destination of size 128
   71 |   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   72 |                                    __glibc_objsize (__s), __fmt,
      |                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   73 |                                    __va_arg_pack ());
nimgould commented 6 months ago

Yes, I have seen these warning, but my C isn't good enough to know how to fix them. Maybe @jfowkes might know?

jfowkes commented 6 months ago

Well this is old-school C: it's complaining that the string buffer is too small and so could be truncated. I think the simplest solution is just to increase the buffer size:

char buffer[STRING_LENGTH+20];

Please test if this fixes the problem though!

nimgould commented 6 months ago

That works here. Thanks