openDsh / dash

Join us on Slack! https://join.slack.com/t/opendsh/shared_invite/zt-la398uly-a6eMH5ttEQhbtE6asVKx4Q
GNU General Public License v3.0
238 stars 69 forks source link

comparison of integer expressions of different signedness: ‘int’ #81

Closed matt2005 closed 2 years ago

matt2005 commented 2 years ago

Issue

dash/src/canbus/elm327.cpp:144:19: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string::size_type’ {aka ‘unsigned int’} [-Wsign-compare] for(int i=0; i<resp_str.length()/2; i++){

egisz commented 2 years ago

@matt2005, @rsjudka, after this fix, I get error whil compiling in ubuntu dev environment:

[ 46%] Building CXX object CMakeFiles/dash.dir/src/canbus/elm327.cpp.o
/home/egidijusz@OLVINET.drinkgroup.local/src/dash/src/canbus/elm327.cpp: In member function ‘QCanBusFrame elm327::receive()’:
/home/egidijusz@OLVINET.drinkgroup.local/src/dash/src/canbus/elm327.cpp:145:16: error: ambiguous overload for ‘operator[]’ (operand types are ‘QByteArray’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’})
  145 |         payload[i+1] = std::stoi(resp_str.substr(2*i, 2), nullptr, 16);
      |                ^
/home/egidijusz@OLVINET.drinkgroup.local/src/dash/src/canbus/elm327.cpp:145:16: note: candidate: ‘operator[](const char*, long int)’ (built-in)
In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qmetatype.h:47,
                 from /usr/include/x86_64-linux-gnu/qt5/QtSerialBus/qcanbusframe.h:40,
                 from /usr/include/x86_64-linux-gnu/qt5/QtSerialBus/QCanBusFrame:1,
                 from /home/egidijusz@OLVINET.drinkgroup.local/src/dash/include/canbus/elm327.hpp:4,
                 from /home/egidijusz@OLVINET.drinkgroup.local/src/dash/src/canbus/elm327.cpp:1:
/usr/include/x86_64-linux-gnu/qt5/QtCore/qbytearray.h:501:13: note: candidate: ‘char QByteArray::operator[](int) const’
  501 | inline char QByteArray::operator[](int i) const
      |             ^~~~~~~~~~
/usr/include/x86_64-linux-gnu/qt5/QtCore/qbytearray.h:503:13: note: candidate: ‘char QByteArray::operator[](uint) const’
  503 | inline char QByteArray::operator[](uint i) const
      |             ^~~~~~~~~~
/usr/include/x86_64-linux-gnu/qt5/QtCore/qbytearray.h:626:17: note: candidate: ‘QByteRef QByteArray::operator[](int)’
  626 | inline QByteRef QByteArray::operator[](int i)
      |                 ^~~~~~~~~~
/usr/include/x86_64-linux-gnu/qt5/QtCore/qbytearray.h:628:17: note: candidate: ‘QByteRef QByteArray::operator[](uint)’
  628 | inline QByteRef QByteArray::operator[](uint i)
      |                 ^~~~~~~~~~
make[2]: *** [CMakeFiles/dash.dir/build.make:481: CMakeFiles/dash.dir/src/canbus/elm327.cpp.o] Error 1

I believe it would be sufficient to change type to uint: https://github.com/matt2005/dash/blob/70668b52a8c9be20dd08b4591d54cac500e0bb53/src/canbus/elm327.cpp#L144

for( uint i=0; i < resp_str.length()/2; i++){

In this case it compiles.