Skip to content

Commit

Permalink
Fix some issues found by Coverity Scan
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Schlemmer committed Jul 6, 2019
1 parent d528c1f commit 4a22b15
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 58 deletions.
3 changes: 3 additions & 0 deletions src/kernel/routing/gmn/tests/playgmn1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ int main(/* int argc, char **argv */)
} catch (const mutabor::RouteFactory::FactoryAlreadySet & e) {
std::cerr << boost::current_exception_diagnostic_information();
return 1;
} catch (const mutabor::error::unreachable_exception & e) {
std::cerr << boost::current_exception_diagnostic_information();
return 1;
}
mutabor::ScopedInputDevice in;
try {
Expand Down
3 changes: 3 additions & 0 deletions src/kernel/routing/midi/tests/genmidilinear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ int main(/* int argc, char **argv */)
} catch (const mutabor::RouteFactory::FactoryAlreadySet & e) {
std::cerr << boost::current_exception_diagnostic_information();
return 1;
} catch (const mutabor::error::unreachable_exception & e) {
std::cerr << boost::current_exception_diagnostic_information();
return 1;
}
mutabor::CurrentTime.UseRealtime(false);
mutabor::CurrentTime.Set(mutabor::microseconds(0));
Expand Down
3 changes: 3 additions & 0 deletions src/kernel/routing/tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ main()
} catch (const mutabor::RouteFactory::FactoryAlreadySet & e) {
std::cerr << boost::current_exception_diagnostic_information();
return 1;
} catch (const mutabor::error::unreachable_exception & e) {
std::cerr << boost::current_exception_diagnostic_information();
return 1;
}

#ifdef _GLIBCXX_DEBUG
Expand Down
59 changes: 32 additions & 27 deletions src/kernel/routing/tests/test_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,39 +67,44 @@ class test_thread: public Thread {
};

int main() {
test_thread test;
print_status("Before Run");
assert(test.get_command() == Thread::thread_initialized);
assert(test.get_state() == Thread::thread_initialized);
try {
test.Run();
} catch (const boost::condition_error & e) {
std::cerr << boost::current_exception_diagnostic_information();
return 1;
}
test_thread test;
print_status("Before Run");
assert(test.get_command() == Thread::thread_initialized);
assert(test.get_state() == Thread::thread_initialized);
try {
test.Run();
} catch (const boost::condition_error & e) {
std::cerr << boost::current_exception_diagnostic_information();
return 1;
}

assert(test.get_command() == Thread::thread_running);
print_status("After Run");
int retval;
try {
retval = test.Wait();
} catch (const boost::condition_error & e) {
std::cerr << boost::current_exception_diagnostic_information();
return 1;
} catch (const boost::thread_resource_error &) {
std::cerr << boost::current_exception_diagnostic_information();
return 1;
}
assert(test.get_command() == Thread::thread_running);
print_status("After Run");
int retval;
try {
retval = test.Wait();
} catch (const boost::condition_error & e) {
std::cerr << boost::current_exception_diagnostic_information();
return 1;
} catch (const boost::thread_resource_error &) {
std::cerr << boost::current_exception_diagnostic_information();
return 1;
}

try {
boost::unique_lock<boost::mutex> lock(printmutex);
std::cerr << "Wait returns: " << retval << std::endl;
try {
boost::unique_lock<boost::mutex> lock(printmutex);
std::cerr << "Wait returns: " << retval << std::endl;
} catch (const boost::lock_error & e) {
std::cerr << boost::current_exception_diagnostic_information();
return 1;
}
assert(test.get_state() == Thread::thread_finished);
return 0;
} catch (const boost::lock_error & e) {
std::cerr << boost::current_exception_diagnostic_information();
return 1;
return 2;
}
assert(test.get_state() == Thread::thread_finished);
return 0;
}


67 changes: 38 additions & 29 deletions src/kernel/routing/watchdog.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,38 +86,47 @@ namespace mutabor {
}

int Entry() throw() {
ScopedLock<> lock(mutex);
auto cur_time = CurrentTimer::time_point::clock::now();
auto wake_time = cur_time+timeout;
while (!exit && const_cast<targettype&>(target)) {
do {
try {
cond.Sleep(lock, wake_time);
} catch (boost::thread_interrupted) {
exit = true;
break;
} catch (const boost::lock_error & e) {
// rethrow after joining.
state = thread_exception_caught;
exception = std::current_exception();
break;
}
// deal with spurious wakeups.
} while ((cur_time = CurrentTimer::time_point::clock::now()) < wake_time);
if (exit) break;
targettype tmp = const_cast<targettype&>(target);
if (tmp && !exit) {
try {
tmp->dog_watching();
} catch (const boost::lock_error & e) {
// rethrow after joining.
state = thread_exception_caught;
exception = std::current_exception();
try {
ScopedLock<> lock(mutex);
auto cur_time = CurrentTimer::time_point::clock::now();
auto wake_time = cur_time+timeout;
while (!exit && const_cast<targettype&>(target)) {
do {
try {
cond.Sleep(lock, wake_time);
} catch (boost::thread_interrupted) {
exit = true;
break;
} catch (const boost::lock_error & e) {
// rethrow after joining.
state = thread_exception_caught;
exception = std::current_exception();
// exit is untouched
break;
}
// deal with spurious wakeups.
} while ((cur_time = CurrentTimer::time_point::clock::now()) < wake_time);
if (exit) break;
targettype tmp = const_cast<targettype&>(target);
if (tmp && !exit) {
try {
tmp->dog_watching();
} catch (const boost::lock_error & e) {
// rethrow after joining.
state = thread_exception_caught;
exception = std::current_exception();
// exit is untouched
}
}
wake_time = cur_time+timeout;
}
wake_time = cur_time+timeout;
return 0;
} catch (const boost::lock_error & e) {
// rethrow after joining.
state = thread_exception_caught;
exception = std::current_exception();
return 1;
}
return 0;
}

void OnExit() throw() {
Expand Down
4 changes: 2 additions & 2 deletions tools/midi2text/src/midifile.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,9 +704,9 @@ int (*wtrack)();
}

if (place_marker >= 0)
fseek(fp,place_marker,0);
(void)fseek(fp,place_marker,0);
else
fseek(fp,0,SEEK_END);
(void)fseek(fp,0,SEEK_END);
} /* End gen_track_chunk() */

static void
Expand Down

0 comments on commit 4a22b15

Please sign in to comment.