Skip to content

Commit

Permalink
Merge pull request tree-sitter#77 from philipturnbull/scan-build-fixes
Browse files Browse the repository at this point in the history
Fix errors found by scan-build
  • Loading branch information
Max Brunsfeld authored Jun 20, 2017
2 parents f29c41b + 7bdb091 commit 513edec
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 10 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
sudo: false
dist: trusty
language: cpp
compiler:
- gcc
Expand All @@ -9,10 +10,11 @@ addons:
- ubuntu-toolchain-r-test
packages:
- g++-5
- clang

install:
- export CXX="g++-5"
- script/configure
- scan-build script/configure

script:
- script/ci
Expand Down
4 changes: 3 additions & 1 deletion script/ci
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -e

. script/lib.sh

script/fetch-fixtures
script/check-mallocs
script/test
script/test -b
26 changes: 26 additions & 0 deletions script/lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

function scan_build {
extra_args=()

# AFAICT, in the trusty travis container the scan-build tool is from the 3.4
# installation. Therefore, by default it will use clang-3.4 when analysing code
# which doesn't support the '-std=c++14' (it is available via '-std=c++1y').
# Use the system-wide installed clang instead which is 3.5 and does support
# '-std=c++14'.
extra_args+=("--use-analyzer=$(which clang)")

# scan-build will try to guess which CXX should be used to compile the actual
# code, which is usually g++ but we need g++5 in the CI. Explicitly pass
# $CC/$CXX to scan-build if they are set in the environment.

if [[ ! -z "$CC" ]]; then
extra_args+=("--use-cc=$CC")
fi

if [[ ! -z "$CXX" ]]; then
extra_args+=("--use-c++=$CXX")
fi

scan-build "${extra_args[@]}" --status-bugs -disable-checker deadcode.DeadStores "$@"
}
17 changes: 15 additions & 2 deletions script/test
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -e

. script/lib.sh

function usage {
cat <<-EOF
USAGE
Expand All @@ -12,6 +14,8 @@ OPTIONS
-h print this message
-b run make under scan-build static analyzer
-d run tests in a debugger (either lldb or gdb)
-g run tests with valgrind's memcheck tool
Expand All @@ -26,6 +30,7 @@ OPTIONS
-z pipe tests' stderr to \`dot(1)\` to render an SVG log
EOF
}

Expand All @@ -37,8 +42,9 @@ args=()
target=tests
export BUILDTYPE=Test
cmd="out/${BUILDTYPE}/${target}"
run_scan_build=

while getopts "df:s:gGhpvS" option; do
while getopts "bdf:s:gGhpvS" option; do
case ${option} in
h)
usage
Expand Down Expand Up @@ -69,6 +75,9 @@ while getopts "df:s:gGhpvS" option; do
S)
mode=SVG
;;
b)
run_scan_build=true
;;
esac
done

Expand All @@ -78,7 +87,11 @@ else
args+=("--reporter=singleline")
fi

make $target
if [[ -n "$run_scan_build" ]]; then
scan_build make -j2 $target
else
make -j2 $target
fi
args=${args:-""}

if [[ -n $profile ]]; then
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/build_tables/build_parse_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,8 @@ class ParseTableBuilder {
if (considered_associativity) {
description += " " + to_string(resolution_count++) + ": ";
description += "Specify a left or right associativity in";
bool is_first = true;
for (const ParseAction &action : entry.actions) {
bool is_first = true;
if (action.type == ParseActionTypeReduce) {
if (!is_first) description += " and";
description += " `" + symbol_name(action.symbol) + "`";
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ static StackIterateAction parser__repair_error_callback(
StackIterateAction result = StackIterateNone;

uint32_t last_repair_count = -1;
uint32_t repair_reduction_count = -1;
uint32_t repair_reduction_count = 0;
const TSParseAction *repair_reductions = NULL;

for (uint32_t i = 0; i < repairs->size; i++) {
Expand Down Expand Up @@ -845,7 +845,7 @@ static void parser__accept(Parser *self, StackVersion version,

if (parser__select_tree(self, self->finished_tree, root)) {
ts_tree_release(self->finished_tree);
assert(root->ref_count > 0);
assert(root && root->ref_count > 0);
self->finished_tree = root;
} else {
ts_tree_release(root);
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/record_alloc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ void *ts_record_calloc(size_t count, size_t size) {
}

void ts_record_free(void *pointer) {
free(pointer);
record_deallocation(pointer);
free(pointer);
}

bool ts_record_allocations_toggle(bool value) {
Expand Down
4 changes: 2 additions & 2 deletions test/runtime/document_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ describe("Document", [&]() {
ts_document_set_language(document, load_real_language("json"));
ts_document_set_input_string(document, input_string.c_str());

TSParseOptions options;
TSParseOptions options = {};
options.changed_ranges = nullptr;

options.halt_on_error = false;
Expand Down Expand Up @@ -413,7 +413,7 @@ describe("Document", [&]() {
ts_document_set_language(document, load_real_language("json"));
ts_document_set_input_string(document, input_string.c_str());

TSParseOptions options;
TSParseOptions options = {};
options.changed_ranges = nullptr;
options.halt_on_error = true;
ts_document_parse_with_options(document, options);
Expand Down

0 comments on commit 513edec

Please sign in to comment.