mctools / ncrystal

NCrystal : a library for thermal neutron transport in crystals and other materials
https://mctools.github.io/ncrystal/
Other
38 stars 17 forks source link

cppcheck issues #165

Closed tkittel closed 2 months ago

tkittel commented 4 months ago

cppcheck uncovered a few issues:

/some/where/include/NCrystal/NCFmt.hh:81:14: error: Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]
      return ShortStr( &cdata[0], ( cdata[N-1]=='\0' ? N-1 : N ) );
             ^
/some/where/include/NCrystal/NCMem.hh:151:7: error: Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]
      check_nonnull();
      ^
/some/where/include/NCrystal/NCMem.hh:166:98: error: Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]
    ncconstexpr17 shared_obj( std::shared_ptr<TOther>&& sp ) noexcept : m_shptr(std::move(sp)) { check_nonnull(); }
                                                                                                 ^
/some/where/include/NCrystal/NCMem.hh:169:92: error: Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]
    ncconstexpr17 shared_obj( const std::shared_ptr<TOther>& sp ) noexcept : m_shptr(sp) { check_nonnull(); }
                                                                                           ^
/some/where/include/NCrystal/NCMem.hh:175:7: error: Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]
      check_nonnull();
      ^
/some/where/include/NCrystal/NCMem.hh:183:7: error: Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]
      check_nonnull();
      ^
/some/where/include/NCrystal/NCMatCfg.hh:434:70: error: Reference to temporary returned. [returnTempReference]
  inline const TextData& MatCfg::textData() const { return textDataSP(); }
                                                                     ^
/some/where/include/NCrystal/internal/NCCfgTypes.hh:95:94: error: Null pointer dereference: (value_type*)(nullptr) [nullPointer]
        static constexpr value_type dvon( NullOptType ) { return nc_assert_always_rv(false),*(value_type*)(nullptr); }//won't actually get called

We need to be careful, since the public API is involved.

tkittel commented 2 months ago

Fixed in 3.8.1, and cppcheck now used in CI.