daniele77 / cli

A library for interactive command line interfaces in modern C++
Boost Software License 1.0
1.24k stars 140 forks source link

integer overflow warning is detected by clang++ #236

Closed redboltz closed 7 months ago

redboltz commented 8 months ago

I got integer overflow warning at detail/fromstring.h:134 on the following environment.

Environment

cli version

master 9373d0b378fce1c005222294075ffe178c3fc4c

OS

Linux archlinux 6.8.1-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 16 Mar 2024 17:15:35 +0000 x86_64 GNU/Linux

Compiler

clang version 17.0.6 Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin

Reproduce

mkdir build
cd build
cmake -DCMAKE_CXX_COMPILER=clang++ -DCLI_BuildTests=ON  .. && make   

Warning

/home/kondo/work/cli/include/cli/detail/../detail/fromstring.h:134:36: warning: overflow in expression; result is -2147483648 with type 'int' [-Winteger-overflow]
  134 |         if ( val > static_cast<U>( - std::numeric_limits<T>::min() ) )
      |                                    ^
/home/kondo/work/cli/include/cli/detail/../detail/fromstring.h:134:36: warning: overflow in expression; result is -9223372036854775808 with type 'long' [-Winteger-overflow]
/home/kondo/work/cli/include/cli/detail/../detail/fromstring.h:134:36: warning: overflow in expression; result is -9223372036854775808 with type 'long long' [-Winteger-overflow]
daniele77 commented 7 months ago

I have addressed this. Please test the new commit ee14ce0 in your environment and confirm if the issue has indeed been resolved. By the way, thank you very much for the detailed information you provided when filing the issue.

redboltz commented 7 months ago

At the following commit:

commit ee14ce04ca2cfd4ea735e80530816f9eda1ae520 (HEAD -> master, origin/master, origin/HEAD)
Author: Daniele Pallastrelli <5451767+daniele77@users.noreply.github.com>
Date:   Wed Apr 3 10:45:54 2024 +0200

    close #236 (Integer overflow warning detected by clang++)

I got the following warnings:

[  5%] Building CXX object examples/CMakeFiles/pluginmanager.dir/pluginmanager.cpp.o
cd /home/kondo/work/cli/clb/examples && /usr/bin/clang++ -DCLI_EXAMPLES_USE_LOOP_SCHEDULER -I/home/kondo/work/cli/include  -MD -MT examples/CMakeFiles/pluginmanager.dir/pluginmanager.cpp.o -MF CMakeFiles/pluginmanager.dir/pluginmanager.cpp.o.d -o CMakeFiles/pluginmanager.dir/pluginmanager.cpp.o -c /home/kondo/work/cli/examples/pluginmanager.cpp
/home/kondo/work/cli/examples/pluginmanager.cpp:101:31: warning: unqualified call to 'std::move' [-Wunqualified-std-cast-call]
  101 |             plugins.push_back(move(p));
      |                               ^
      |                               std::
/home/kondo/work/cli/examples/pluginmanager.cpp:190:36: warning: unqualified call to 'std::move' [-Wunqualified-std-cast-call]
  190 |         menuHandler = menu->Insert(move(subMenu));
      |                                    ^
      |                                    std::
/home/kondo/work/cli/examples/pluginmanager.cpp:240:36: warning: unqualified call to 'std::move' [-Wunqualified-std-cast-call]
  240 |         menuHandler = menu->Insert(move(subMenu));
      |                                    ^
      |                                    std::
In file included from /home/kondo/work/cli/examples/pluginmanager.cpp:45:
In file included from /home/kondo/work/cli/include/cli/clilocalsession.h:34:
In file included from /home/kondo/work/cli/include/cli/detail/inputhandler.h:37:
In file included from /home/kondo/work/cli/include/cli/detail/../cli.h:43:
/home/kondo/work/cli/include/cli/detail/../detail/fromstring.h:135:36: warning: overflow in expression; result is -2147483648 with type 'int' [-Winteger-overflow]
  135 |         if ( val > static_cast<U>( - min ) )
      |                                    ^
/home/kondo/work/cli/include/cli/detail/../detail/fromstring.h:135:36: warning: overflow in expression; result is -9223372036854775808 with type 'long' [-Winteger-overflow]
/home/kondo/work/cli/include/cli/detail/../detail/fromstring.h:135:36: warning: overflow in expression; result is -9223372036854775808 with type 'long long' [-Winteger-overflow]
6 warnings generated.

It seems that integer overflow warning still happens.

daniele77 commented 7 months ago

Please, can you try again the last commit? (af87753)

redboltz commented 7 months ago

The warnings are disappeared. Thank you!