Skip to content

Instantly share code, notes, and snippets.

@Neisoweli
Last active June 4, 2020 15:51
Show Gist options
  • Save Neisoweli/0ab2a80c17ff177e6dea2543c518e74b to your computer and use it in GitHub Desktop.
Save Neisoweli/0ab2a80c17ff177e6dea2543c518e74b to your computer and use it in GitHub Desktop.
Lab15.Report

Laboratory work XV

Данная лабораторная работа посвещена изучению инструментов статического и динамического анализа кода

$ open http://cppcheck.sourceforge.net

Tasks

  • 1. Ознакомиться со ссылками учебного материала
  • 2. Используя cpplint провести анализ проекта на C++
  • 3. Используя Cppcheck провести анализ проекта на C++
  • 4. Используя OCLint провести анализ проекта на C++
  • 5. Используя Valgrind провести анализ проекта на C++
  • 6. Составить отчет и отправить ссылку личным сообщением в Slack

Tutorial

Копируем репозиторий в директорию lab15

$ git clone https://github.com/${GITHUB_USERNAME}/Labs lab15
$ cd lab15
$ git checkout lab13
$ cmake -H. -B_build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=_install -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
$ cmake --build _build
$ cmake --build _build --target install

Устанавливаем cpplint

$ sudo apt-get install python-pip
$ pip install cpplint

Производим анализ проекта используя cpplint

$ cpplint source/demo.cpp
/sources/demo.cpp:0:  No copyright message found.  You should have a line: "Copyright [year] <Copyright Owner>"  [legal/copyright] [5]
/sources/demo.cpp:2:  Found C++ system header after other header. Should be: demo.h, c system, c++ system, other.  [build/include_order] [4]
/sources/demo.cpp:5:  Static/global string variables are not permitted.  [runtime/string] [4]
/sources/demo.cpp:6:  Static/global string variables are not permitted.  [runtime/string] [4]
Done processing lab15/sources/demo.cpp
Total errors found: 4

Устанавливаем Cppcheck

$ sudo apt-get install cppcheck

Производим анализ проекта используя Cppcheck

$ cppcheck --enable=all --inconclusive --check-config --std=c++11 sources/demo.cpp
Checking sources/demo.cpp ...
[sources/demo.cpp:1]: (information) Include file: <print.hpp> not found. Please note: Cppcheck does not need standard library headers to get proper results.
[sources/demo.cpp:2]: (information) Include file: <cstdlib> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Устанавливаем OCLint

$ wget https://github.com/oclint/oclint/releases/download/v0.13.1/oclint-0.13.1-x86_64-linux-4.4.0-112-generic.tar.gz
$ tar -xzvf oclint-0.13.1-x86_64-linux-4.4.0-112-generic.tar.gz 
$ rm -rf oclint-0.13.1-x86_64-linux-4.4.0-112-generic.tar.gz
$ export OCLINT_HOME=`pwd`/oclint-0.13.1/bin/oclint/oclint-0.13.1
$ export PATH=$OCLINT_HOME/bin:$PATH

Производим анализ проекта используя OCLint

$ oclint -p=_build sources/demo.cpp
OCLint Report

Summary: TotalFiles=1 FilesWithViolations=1 P1=0 P2=0 P3=2 

/home/nei-chan/workspace/project/lab15/sources/demo.cpp:4:10: unused method parameter [unused|P3] The parameter 'argc' is unused.
/home/nei-chan/workspace/project/lab15/sources/demo.cpp:4:20: unused method parameter [unused|P3] The parameter 'argv' is unused.

[OCLint (http://oclint.org) v0.13.1]

Устанавливаем Valgrind

$ sudo apt-get install valgrind

Производим анализ проекта используя Valgrind

$ valgrind _build/demo
==32080== Memcheck, a memory error detector
==32080== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==32080== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==32080== Command: lab15/_build/demo
==32080== 
terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string::_M_construct null not valid
==32080== 
==32080== Process terminating with default action of signal 6 (SIGABRT)
==32080==    at 0x54100BB: raise (raise.c:51)
==32080==    by 0x5411F5C: abort (abort.c:90)
==32080==    by 0x4ECE094: __gnu_cxx::__verbose_terminate_handler() (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.24)
==32080==    by 0x4ECBC85: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.24)
==32080==    by 0x4ECBCD0: std::terminate() (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.24)
==32080==    by 0x4ECBF13: __cxa_throw (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.24)
==32080==    by 0x4EF57BE: std::__throw_logic_error(char const*) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.24)
==32080==    by 0x109314: main (in /home/nei-chan/workspace/project/lab15/_build/demo)
==32080== 
==32080== HEAP SUMMARY:
==32080==     in use at exit: 210 bytes in 2 blocks
==32080==   total heap usage: 4 allocs, 2 frees, 72,946 bytes allocated
==32080== 
==32080== LEAK SUMMARY:
==32080==    definitely lost: 0 bytes in 0 blocks
==32080==    indirectly lost: 0 bytes in 0 blocks
==32080==      possibly lost: 144 bytes in 1 blocks
==32080==    still reachable: 66 bytes in 1 blocks
==32080==                       of which reachable via heuristic:
==32080==                         stdstring          : 66 bytes in 1 blocks
==32080==         suppressed: 0 bytes in 0 blocks
==32080== Rerun with --leak-check=full to see details of leaked memory
==32080== 
==32080== For counts of detected and suppressed errors, rerun with: -v
==32080== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Links

Copyright (c) 2017 Братья Вершинины
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment