[gjs: 6/11] profiler: Suppress cppcheck warning
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 6/11] profiler: Suppress cppcheck warning
- Date: Thu, 25 Jan 2018 01:22:43 +0000 (UTC)
commit 12b5a8f93cf398f57075035b894c4c970aa5ec4d
Author: Philip Chimento <philip endlessm com>
Date: Thu Jan 18 16:46:27 2018 -0800
profiler: Suppress cppcheck warning
The cppcheck program will warn about alloca() even though there's no
equivalent alternative in C++. I don't think there's necessarily a better
way to do this, so we suppress the warning and add a justification.
Makefile.am | 4 +++-
gjs/profiler.cpp | 9 +++++++++
test/test-ci.sh | 4 ++--
3 files changed, 14 insertions(+), 3 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index ef4daeb..e4e661c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -212,6 +212,8 @@ CPPCHECK=cppcheck
### cppcheck static code analysis
#
cppcheck:
- $(CPPCHECK) --enable=warning,performance,portability,information,missingInclude --force -q
$(top_srcdir) -I $(top_builddir)
+ $(CPPCHECK) --inline-suppr \
+ --enable=warning,performance,portability,information,missingInclude \
+ --force -q $(top_srcdir) -I $(top_builddir)
-include $(top_srcdir)/git.mk
diff --git a/gjs/profiler.cpp b/gjs/profiler.cpp
index c199179..1ee9220 100644
--- a/gjs/profiler.cpp
+++ b/gjs/profiler.cpp
@@ -291,6 +291,15 @@ gjs_profiler_sigprof(int signum,
"in an unsigned short");
int64_t now = g_get_monotonic_time() * 1000L;
+
+ /* NOTE: cppcheck warns that alloca() is not recommended since it can
+ * easily overflow the stack; however, dynamic allocation is not an option
+ * here since we are in a signal handler.
+ * Another option would be to always allocate G_N_ELEMENTS(self->stack),
+ * but that is by definition at least as large of an allocation and
+ * therefore is more likely to overflow.
+ */
+ // cppcheck-suppress allocaCalled
SpCaptureAddress *addrs = static_cast<SpCaptureAddress *>(alloca(sizeof *addrs * depth));
for (size_t ix = 0; ix < depth; ix++) {
diff --git a/test/test-ci.sh b/test/test-ci.sh
index 25c7742..1d58593 100755
--- a/test/test-ci.sh
+++ b/test/test-ci.sh
@@ -137,13 +137,13 @@ elif [[ $1 == "GJS_COVERAGE" ]]; then
elif [[ $1 == "CPPCHECK" ]]; then
echo
echo '-- Static code analyzer report --'
- cppcheck --enable=warning,performance,portability,information,missingInclude --force -q . 2>&1 | \
+ cppcheck --inline-suppr --enable=warning,performance,portability,information,missingInclude --force -q .
2>&1 | \
sed -E 's/:[0-9]+]/:LINE]/' | tee /cwd/current-report.txt
echo
echo '-- Master static code analyzer report --'
git clone --depth 1 https://gitlab.gnome.org/GNOME/gjs.git tmp-upstream; cd tmp-upstream || exit 1
- cppcheck --enable=warning,performance,portability,information,missingInclude --force -q . 2>&1 | \
+ cppcheck --inline-suppr --enable=warning,performance,portability,information,missingInclude --force -q .
2>&1 | \
sed -E 's/:[0-9]+]/:LINE]/' | tee /cwd/master-report.txt
echo
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]