Skip to content

Commit

Permalink
Solved issues reported by static analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
torrentg committed Dec 28, 2022
1 parent 632081f commit 5b540c8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ example: cstring-example.cpp
./cstring-example

tests: cstring-tests.cpp
$(CXX) -fsanitize=address -g $(CXXFLAGS) -o cstring-tests cstring-tests.cpp
$(CXX) -fsanitize=address,undefined -g $(CXXFLAGS) -o cstring-tests cstring-tests.cpp -lasan -lubsan
./cstring-tests

coverage: cstring-tests.cpp
Expand All @@ -19,6 +19,10 @@ coverage: cstring-tests.cpp
lcov --remove coverage/coverage.info '*/cstring-tests.cpp' -o coverage/coverage.info
genhtml -o coverage coverage/coverage.info

static-analysis: cstring.hpp
cppcheck --enable=all --inconclusive --suppress=unusedFunction --suppress=passedByValue --suppress=noExplicitConstructor --suppress=missingIncludeSystem cstring.hpp
clang-tidy cstring.hpp -checks='-*,readability-*,-readability-redundant-access-specifiers,-readability-identifier-length,-readability-braces-around-statements,performance-*,portability-*,misc-*,clang-analyzer-*,bugprone-*,-clang-diagnostic-error' -extra-arg=-std=c++20

clean:
rm -f cstring-tests
rm -f cstring-coverage
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Main drawbacks:

Drop off [`cstring.hpp`](cstring.hpp) in your project and start using the cstring.

Read [`example.cpp`](example.cpp) file to see how to use it.
Read [`cstring-example.cpp`](cstring-example.cpp) file to see how to use it.

```c++
#include "cstring.hpp"
Expand Down
5 changes: 3 additions & 2 deletions cstring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace gto {
* @see https://en.cppreference.com/w/cpp/string/basic_string
* @see https://github.com/torrentg/cstring
* @note This class is immutable.
* @version 1.0.0
* @version 1.0.1
*/
template<typename Char,
typename Traits = std::char_traits<Char>,
Expand Down Expand Up @@ -223,7 +223,8 @@ class basic_cstring
basic_cstring(const_pointer str, size_type len) {
if (len > max_size()) {
throw std::length_error("invalid cstring length");
} else if (str == nullptr || len == 0) {
}
if (str == nullptr || len == 0) {
mStr = mEmpty.str;
} else {
size_type n = getAllocatedLength(len);
Expand Down

0 comments on commit 5b540c8

Please sign in to comment.