Warning: require() [function.require]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 194

Warning: require() [function.require]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 195

Warning: require() [function.require]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 196

Warning: require() [function.require]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-includes/class-http.php on line 11

Warning: require() [function.require]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 197

Warning: require() [function.require]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 198

Warning: require() [function.require]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 199

Warning: require() [function.require]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 200

Warning: require() [function.require]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 201

Warning: require() [function.require]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 202

Warning: require() [function.require]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 203

Warning: require() [function.require]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 204

Warning: require() [function.require]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 205

Warning: require() [function.require]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 206

Warning: require() [function.require]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 207

Warning: require() [function.require]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 208

Warning: require_once() [function.require-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-includes/nav-menu-template.php on line 11

Warning: require() [function.require]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 209

Warning: require() [function.require]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 210

Warning: require() [function.require]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 211

Warning: require() [function.require]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 212

Warning: require() [function.require]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 213

Warning: require() [function.require]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 260

Warning: include_once() [function.include-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 273

Warning: require_once() [function.require-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-content/plugins/akismet/akismet.php on line 48

Warning: require_once() [function.require-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-content/plugins/akismet/akismet.php on line 49

Warning: require_once() [function.require-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-content/plugins/akismet/akismet.php on line 59

Warning: include_once() [function.include-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 273

Warning: require_once() [function.require-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-content/plugins/google-sitemap-generator/sitemap.php on line 73

Warning: include_once() [function.include-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 273

Warning: include_once() [function.include-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 273

Warning: require_once() [function.require-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-content/plugins/wp-mystat/mystat.php on line 15

Warning: require_once() [function.require-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-content/plugins/wp-mystat/index.php on line 5

Warning: require_once() [function.require-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-content/plugins/wp-mystat/lib/mystat.class.php on line 24

Warning: include_once() [function.include-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 273

Warning: include_once() [function.include-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-content/plugins/wp-show-stats/wp-show-stats.php on line 16

Warning: include_once() [function.include-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-content/plugins/wp-show-stats/wp-show-stats.php on line 17

Warning: include_once() [function.include-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-content/plugins/wp-show-stats/wp-show-stats.php on line 18

Warning: include_once() [function.include-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-content/plugins/wp-show-stats/wp-show-stats.php on line 19

Warning: include_once() [function.include-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-content/plugins/wp-show-stats/wp-show-stats.php on line 20

Warning: include_once() [function.include-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-content/plugins/wp-show-stats/wp-show-stats.php on line 21

Warning: include_once() [function.include-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-content/plugins/wp-show-stats/wp-show-stats.php on line 22

Warning: include_once() [function.include-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-content/plugins/wp-show-stats/wp-show-stats.php on line 23

Warning: include_once() [function.include-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 273

Warning: include_once() [function.include-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-content/plugins/wp-super-cache/wp-cache.php on line 82

Warning: include_once() [function.include-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 273

Warning: require() [function.require]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 278

Warning: require() [function.require]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 279

Warning: Cannot modify header information - headers already sent by (output started at /home/c/cl11353/public_html/wp-settings.php:194) in /home/c/cl11353/public_html/wp-content/plugins/wp-super-cache/wp-cache-phase2.php on line 62

Warning: require_once() [function.require-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-includes/default-widgets.php on line 20

Warning: require_once() [function.require-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-includes/default-widgets.php on line 32

Warning: require_once() [function.require-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-includes/default-widgets.php on line 35

Warning: require_once() [function.require-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-includes/default-widgets.php on line 38

Warning: require_once() [function.require-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-includes/default-widgets.php on line 41

Warning: require_once() [function.require-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-includes/default-widgets.php on line 47

Warning: include_once() [function.include-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-content/plugins/wp-syntax/wp-syntax.php on line 143

Warning: require_once() [function.require-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-includes/locale.php on line 11

Warning: include() [function.include]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-settings.php on line 387

Warning: require_once() [function.require-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-blog-header.php on line 19

Warning: include() [function.include]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-includes/template-loader.php on line 75

Warning: require_once() [function.require-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-includes/template.php on line 572
Использование Cppcheck для статического анализа кода в блоге Личный опыт разработки ПО

Личный опыт разработки ПО

Сборник рецептов

Использование Cppcheck для статического анализа кода

комментария 2

Что такое статический анализатор кода? Это программа, которая проверяет исходный код программы и пытается найти в нем ошибки. Иногда это у нее ловко получается. Диагностируются выходы за границы массивов, утечки памяти, использование неинициализированных переменных и прочие неприятные вещи. Часто минутный прогон программы позволяет сэкономить час работы в отладчике в поисках бага.

Цена вопроса

Есть программы которые стоят немалых денег (Coverity Prevent for C/C++, Klocwork), а есть абсолютно бесплатные (Cppcheck).

Платные я не тестировал, но судя по статье, Cppcheck им нисколько не уступает. Так на тесте приведенном в указанной статье она находит все ошибки. Вот результат работы:

Checking check.cpp... 
[check.cpp:11]: (error) Array 'c[10]' index 10 out of bounds 
[check.cpp:5]: (error) Memory leak: __p 
[check.cpp:17]: (error) Memory leak: a 
[check.cpp:14]: (error) Mismatching allocation and deallocation: A::__p 
[check.cpp:8]: (error) Null pointer dereference 

 

Кроме затрат материальных, у инструментов есть определенный уровень вхождения, который некоторых может остановить. Я человек ленивый, поэтому мне особенно приятно, что у данного инструмента этот порог очень низкий.

Есть версия программы с графическим интерфейсом, где единственное усилие которое нужно сделать – выбрать пункт меню Check->Files для проверки одного файла, или Check->Directory для проверки всей директории, после чего просмотреть результаты работы.

Также есть консольная версия, на вход которой также достаточно подать  имена проверяемых файлов.

Интеграция в систему сборки

Уже упомянутую консольную версию программы легко добавить в скрипт сборки проекта, чтобы автоматически проводить проверку. При этом Cppcheck может в случае нахождения ошибок вернуть определенный код. Используйте для этого ключ —error-exitcode=код_возврата.

Вывод

Cppcheck отличный инструмент, очень простой в использовании, бесплатный и довольно эффективный. Крайне рекомендую к использованию. Есть версии как для Windows, так и для Linux.

Домашняя страница проекта: http://cppcheck.sourceforge.net/

27th Январь 2011
21:29

Рубрика: C++,Инструменты

Метки: ,


Warning: require() [function.require]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-includes/comment-template.php on line 1469

2 комментария к 'Использование Cppcheck для статического анализа кода'

Подписаться на комментарии по RSS или TrackBack.

  1. Не желаете попробовать наш инструмент PVS-Studio (ссылок не даю, ибо спам-фильтры не дремлют)? Можем предоставить полноценную лицензию на несколько месяцев.

    Евгений Рыжков

    31 марта 11 14:53

  2. Удобный анализатор, давно юзаю.

    nomad

    26 мая 12 19:16

Оставить комментарий


Warning: require_once() [function.require-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-includes/template.php on line 572

Warning: require_once() [function.require-once]: Unable to allocate memory for pool. in /home/c/cl11353/public_html/wp-includes/template.php on line 572