Bug Summary

File:receiver.c
Location:line 28, column 17
Description:Dereference of null pointer

Annotated Source Code

1/*
2 * receiver.c: The basic receiver interface
3 *
4 * See the main source file 'vdr.c' for copyright information and
5 * how to reach the author.
6 *
7 * $Id: receiver.c 3.1 2014/01/01 12:03:00 kls Exp $
8 */
9
10#include "receiver.h"
11#include <stdio.h>
12#include "tools.h"
13
14cReceiver::cReceiver(const cChannel *Channel, int Priority)
15{
16 device = NULL__null;
17 priority = constrain(Priority, MINPRIORITY(-99), MAXPRIORITY99);
18 numPids = 0;
19 SetPids(Channel);
20}
21
22cReceiver::~cReceiver()
23{
24 if (device) {
1
Taking true branch
25 const char *msg = "ERROR: cReceiver has not been detached yet! This is a design fault and VDR will segfault now!";
26 esyslog("%s", msg)void( (SysLogLevel > 0) ? syslog_with_tid(3, "%s", msg) : void
() )
;
27 fprintf(stderrstderr, "%s\n", msg);
28 *(char *)0 = 0; // cause a segfault
2
Dereference of null pointer
29 }
30}
31
32bool cReceiver::AddPid(int Pid)
33{
34 if (Pid) {
35 if (numPids < MAXRECEIVEPIDS64)
36 pids[numPids++] = Pid;
37 else {
38 dsyslog("too many PIDs in cReceiver (Pid = %d)", Pid)void( (SysLogLevel > 2) ? syslog_with_tid(7, "too many PIDs in cReceiver (Pid = %d)"
, Pid) : void() )
;
39 return false;
40 }
41 }
42 return true;
43}
44
45bool cReceiver::AddPids(const int *Pids)
46{
47 if (Pids) {
48 while (*Pids) {
49 if (!AddPid(*Pids++))
50 return false;
51 }
52 }
53 return true;
54}
55
56bool cReceiver::AddPids(int Pid1, int Pid2, int Pid3, int Pid4, int Pid5, int Pid6, int Pid7, int Pid8, int Pid9)
57{
58 return AddPid(Pid1) && AddPid(Pid2) && AddPid(Pid3) && AddPid(Pid4) && AddPid(Pid5) && AddPid(Pid6) && AddPid(Pid7) && AddPid(Pid8) && AddPid(Pid9);
59}
60
61bool cReceiver::SetPids(const cChannel *Channel)
62{
63 numPids = 0;
64 if (Channel) {
65 channelID = Channel->GetChannelID();
66 return AddPid(Channel->Vpid()) &&
67 (Channel->Ppid() == Channel->Vpid() || AddPid(Channel->Ppid())) &&
68 AddPids(Channel->Apids()) &&
69 AddPids(Channel->Dpids()) &&
70 AddPids(Channel->Spids());
71 }
72 return true;
73}
74
75void cReceiver::DelPid(int Pid)
76{
77 if (Pid) {
78 for (int i = 0; i < numPids; i++) {
79 if (pids[i] == Pid) {
80 for ( ; i < numPids; i++) // we also copy the terminating 0!
81 pids[i] = pids[i + 1];
82 numPids--;
83 return;
84 }
85 }
86 }
87}
88
89void cReceiver::DelPids(const int *Pids)
90{
91 if (Pids) {
92 while (*Pids)
93 DelPid(*Pids++);
94 }
95}
96
97bool cReceiver::WantsPid(int Pid)
98{
99 if (Pid) {
100 for (int i = 0; i < numPids; i++) {
101 if (pids[i] == Pid)
102 return true;
103 }
104 }
105 return false;
106}
107
108void cReceiver::Detach(void)
109{
110 if (device)
111 device->Detach(this);
112}