Skip to content

Commit dd0bdda

Browse files
cataliniiCatalin Toda
andauthored
Fix some coverity issues (#1308)
Co-authored-by: Catalin Toda <[email protected]>
1 parent 019d667 commit dd0bdda

File tree

5 files changed

+11
-17
lines changed

5 files changed

+11
-17
lines changed

src/adapter.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,8 @@ adapter *adapter_alloc() {
107107

108108
ad->drop_encrypted = opts.drop_encrypted;
109109

110-
if (!ad->buf) {
111-
ad->lbuf = opts.adapter_buffer;
112-
ad->buf = (unsigned char *)malloc(ad->lbuf + 10);
113-
}
110+
ad->lbuf = opts.adapter_buffer;
111+
ad->buf = (unsigned char *)malloc(ad->lbuf + 10);
114112

115113
#ifndef DISABLE_PMT
116114
// filter for pid 0
@@ -338,11 +336,10 @@ int init_hw(int i) {
338336

339337
int init_all_hw() {
340338
int i, rv;
341-
339+
std::lock_guard<SMutex> lock(a_mutex);
342340
LOG("starting init_all_hw %d", init_complete);
343341
if (init_complete)
344342
return num_adapters;
345-
std::lock_guard<SMutex> lock(a_mutex);
346343
find_adapters();
347344
num_adapters = 0;
348345
init_complete = 1;

src/ddci.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void dump_mapping_table() {
164164
for (const auto &elem : m.pmt)
165165
out += std::to_string(elem) + " ";
166166

167-
LOGM("DD %d, ddpid %d, adapter %d pid %d, rewrite %d: %d PMTS "
167+
LOGM("DD %d, ddpid %d, adapter %d pid %d, rewrite %d: %zu PMTS "
168168
"%s",
169169
m.ddci, m.ddci_pid, m.ad, m.pid, m.rewrite, m.pmt.size(),
170170
out.c_str());

src/dvb.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ int dvb_demux_set_pid(adapter *a, int i_pid) {
14431443
}
14441444
LOG("AD %d [dvr %d %d], setting filter on PID %d for fd %d, active "
14451445
"pids %d",
1446-
a->id, i_pid, fd, a->active_pids);
1446+
a->id, a->pa, a->fn, i_pid, fd, a->active_pids);
14471447
return fd;
14481448
}
14491449

src/socketworks.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -552,15 +552,16 @@ int sockets_add(int sock, USockAddr *sa, int sid, int type, socket_action a,
552552
int sockets_del(int sock) {
553553
int i, so;
554554
sockets *ss;
555+
std::unique_lock<SMutex> lock(s_mutex);
555556

556557
if (sock < 0 || sock >= MAX_SOCKS || !s[sock] || !s[sock]->enabled ||
557-
!s[sock]->is_enabled)
558+
!s[sock]->is_enabled) {
558559
return 0;
560+
}
559561

560562
ss = s[sock];
561-
mutex_lock(&ss->mutex);
563+
std::unique_lock<SMutex> lock2(ss->mutex);
562564
if (!ss->enabled) {
563-
mutex_unlock(&ss->mutex);
564565
return 0;
565566
}
566567
if (ss->close)
@@ -602,10 +603,9 @@ int sockets_del(int sock) {
602603
"%d",
603604
sock, i, so);
604605

605-
mutex_lock(&s_mutex);
606606
ss->enabled = 0;
607-
mutex_unlock(&s_mutex);
608-
mutex_unlock(&ss->mutex);
607+
lock2.unlock();
608+
lock.unlock();
609609

610610
for (i = 0; i < MAX_SOCKS; i++)
611611
if (s[i] && s[i]->enabled && s[i]->master == sock) {

src/utils.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,6 @@ int find_new_id(void **arr, int count) {
519519
struct struct_array **sa = (struct struct_array **)arr;
520520
for (i = 0; i < count; i++)
521521
if (!sa[i] || !sa[i]->enabled) {
522-
if (!sa[i]) {
523-
return i;
524-
}
525522
return i;
526523
}
527524
return -1;

0 commit comments

Comments
 (0)