Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile errors with clang (-Werror) #77

Closed
LiSongMWO opened this issue Nov 1, 2021 · 5 comments · Fixed by #78
Closed

Compile errors with clang (-Werror) #77

LiSongMWO opened this issue Nov 1, 2021 · 5 comments · Fixed by #78

Comments

@LiSongMWO
Copy link

Describe the bug:
When attempting to compile the library using clang++ the compilation quickly fails due to warnings being treated as errors.

To Reproduce:
Steps to reproduce the behavior:

  1. git clone
  2. install clang
  3. make sure clang is selected by cmake
  4. build

Expected behavior:
The source code compiles with clang out of the box

Console log/Error message:

/home/emily/src/photon-hue/hueplusplus/lib/mbedtls/library/error.c: In function ‘mbedtls_strerror’:
/home/emily/src/photon-hue/hueplusplus/lib/mbedtls/library/error.c:921:47: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
  921 |             mbedtls_snprintf( buf, buflen, "%s", high_level_error_description );
      |                                               ^
In file included from /home/emily/src/photon-hue/hueplusplus/lib/mbedtls/library/error.c:29:
/home/emily/src/photon-hue/hueplusplus/lib/mbedtls/include/mbedtls/platform.h:76:41: note: ‘snprintf’ output 1 or more bytes (assuming 2) into a destination of size 1
   76 | #define MBEDTLS_PLATFORM_STD_SNPRINTF   snprintf /**< The default \c snprintf function to use.  */
/home/emily/src/photon-hue/hueplusplus/lib/mbedtls/include/mbedtls/platform.h:243:28: note: in expansion of macro ‘MBEDTLS_PLATFORM_STD_SNPRINTF’
  243 | #define mbedtls_snprintf   MBEDTLS_PLATFORM_STD_SNPRINTF
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/emily/src/photon-hue/hueplusplus/lib/mbedtls/library/error.c:921:13: note: in expansion of macro ‘mbedtls_snprintf’
  921 |             mbedtls_snprintf( buf, buflen, "%s", high_level_error_description );
      |             ^~~~~~~~~~~~~~~~
/home/emily/src/photon-hue/hueplusplus/lib/mbedtls/library/error.c:919:46: error: ‘UNKNOWN ERROR CODE (’ directive output truncated writing 20 bytes into a region of size 1 [-Werror=format-truncation=]
  919 |             mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", (unsigned int) use_ret );
      |                                             ~^~~~~~~~~~~~~~~~~~~
/home/emily/src/photon-hue/hueplusplus/lib/mbedtls/library/error.c:919:44: note: directive argument in the range [1, 65408]
  919 |             mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", (unsigned int) use_ret );
      |                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/emily/src/photon-hue/hueplusplus/lib/mbedtls/library/error.c:29:
/home/emily/src/photon-hue/hueplusplus/lib/mbedtls/include/mbedtls/platform.h:76:41: note: ‘snprintf’ output 26 bytes into a destination of size 1
   76 | #define MBEDTLS_PLATFORM_STD_SNPRINTF   snprintf /**< The default \c snprintf function to use.  */
/home/emily/src/photon-hue/hueplusplus/lib/mbedtls/include/mbedtls/platform.h:243:28: note: in expansion of macro ‘MBEDTLS_PLATFORM_STD_SNPRINTF’
  243 | #define mbedtls_snprintf   MBEDTLS_PLATFORM_STD_SNPRINTF
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/emily/src/photon-hue/hueplusplus/lib/mbedtls/library/error.c:919:13: note: in expansion of macro ‘mbedtls_snprintf’
  919 |             mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", (unsigned int) use_ret );
      |             ^~~~~~~~~~~~~~~~
/home/emily/src/photon-hue/hueplusplus/lib/mbedtls/library/error.c:958:43: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
  958 |         mbedtls_snprintf( buf, buflen, "%s", low_level_error_description );
      |                                           ^
In file included from /home/emily/src/photon-hue/hueplusplus/lib/mbedtls/library/error.c:29:
/home/emily/src/photon-hue/hueplusplus/lib/mbedtls/include/mbedtls/platform.h:76:41: note: ‘snprintf’ output 1 or more bytes (assuming 2) into a destination of size 1
   76 | #define MBEDTLS_PLATFORM_STD_SNPRINTF   snprintf /**< The default \c snprintf function to use.  */
/home/emily/src/photon-hue/hueplusplus/lib/mbedtls/include/mbedtls/platform.h:243:28: note: in expansion of macro ‘MBEDTLS_PLATFORM_STD_SNPRINTF’
  243 | #define mbedtls_snprintf   MBEDTLS_PLATFORM_STD_SNPRINTF
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/emily/src/photon-hue/hueplusplus/lib/mbedtls/library/error.c:958:9: note: in expansion of macro ‘mbedtls_snprintf’
  958 |         mbedtls_snprintf( buf, buflen, "%s", low_level_error_description );
      |         ^~~~~~~~~~~~~~~~
/home/emily/src/photon-hue/hueplusplus/lib/mbedtls/library/error.c:956:42: error: ‘UNKNOWN ERROR CODE (’ directive output truncated writing 20 bytes into a region of size 1 [-Werror=format-truncation=]
  956 |         mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", (unsigned int) use_ret );
      |                                         ~^~~~~~~~~~~~~~~~~~~
/home/emily/src/photon-hue/hueplusplus/lib/mbedtls/library/error.c:956:40: note: directive argument in the range [1, 2147418239]
  956 |         mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", (unsigned int) use_ret );
      |                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/emily/src/photon-hue/hueplusplus/lib/mbedtls/library/error.c:29:
/home/emily/src/photon-hue/hueplusplus/lib/mbedtls/include/mbedtls/platform.h:76:41: note: ‘snprintf’ output between 26 and 30 bytes into a destination of size 1
   76 | #define MBEDTLS_PLATFORM_STD_SNPRINTF   snprintf /**< The default \c snprintf function to use.  */
/home/emily/src/photon-hue/hueplusplus/lib/mbedtls/include/mbedtls/platform.h:243:28: note: in expansion of macro ‘MBEDTLS_PLATFORM_STD_SNPRINTF’
  243 | #define mbedtls_snprintf   MBEDTLS_PLATFORM_STD_SNPRINTF
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/emily/src/photon-hue/hueplusplus/lib/mbedtls/library/error.c:956:9: note: in expansion of macro ‘mbedtls_snprintf’
  956 |         mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", (unsigned int) use_ret );
      |         ^~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

Desktop (please complete the following information):

  • OS: Linux
  • Clang 12.0.1
@Jojo-1000
Copy link
Collaborator

Jojo-1000 commented Nov 2, 2021

Thank you for the bug report,
this seems to be an issue with the version of mbedtls we are using.

Updating to the newest version fixes the error for me:
93ad613 (branch update-mbedtls)

Please verify that this also works on your system.

@LiSongMWO
Copy link
Author

LiSongMWO commented Nov 2, 2021

The code now compiles.

There are a few warnings left that are emitted by hueplusplus:

/home/emily/src/photon-hue/hueplusplus/src/EntertainmentMode.cpp: In constructor ‘hueplusplus::EntertainmentMode::EntertainmentMode(hueplusplus::Bridge&, hueplusplus::Group&)’:
/home/emily/src/photon-hue/hueplusplus/src/EntertainmentMode.cpp:123:9: warning: unused variable ‘ret’ [-Wunused-variable]
  123 |     int ret = mbedtls_ctr_drbg_seed(&tls_context->ctr_drbg, mbedtls_entropy_func, &tls_context->entropy, NULL, 0);
      |         ^~~
/home/emily/src/photon-hue/hueplusplus/src/Scene.cpp: In member function ‘hueplusplus::CreateScene& hueplusplus::CreateScene::setRecycle(bool)’:
/home/emily/src/photon-hue/hueplusplus/src/Scene.cpp:370:43: warning: unused parameter ‘recycle’ [-Wunused-parameter]
  370 | CreateScene& CreateScene::setRecycle(bool recycle)
      |                                      ~~~~~^~~~~~~
/home/emily/src/photon-hue/hueplusplus/src/SimpleColorHueStrategy.cpp: In member function ‘virtual bool hueplusplus::SimpleColorHueStrategy::setColorLoop(bool, hueplusplus::Light&) const’:
/home/emily/src/photon-hue/hueplusplus/src/SimpleColorHueStrategy.cpp:56:48: warning: unused parameter ‘on’ [-Wunused-parameter]
   56 | bool SimpleColorHueStrategy::setColorLoop(bool on, Light& light) const
      |                                           ~~~~~^~

but they do not prevent compilation as hueplusplus doesn't set -Werror by default in the CMakeLists.txt. I consider these "nice to have" clean-ups and they're not blockers for this issue imho.

@LiSongMWO
Copy link
Author

Thanks for the quick turnaround!

@LiSongMWO
Copy link
Author

(not sure if I should close or if you want to fix the warnings above, either way is fine by me)

@enwi
Copy link
Owner

enwi commented Nov 2, 2021

We will close this once it's fixed 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants