Ticket #7059: libs_libmythdb-check-return-ticket-7059

File libs_libmythdb-check-return-ticket-7059, 2.2 KB (added by Erik Hovland <erik@…>, 14 years ago)

Same patch as before but against trunk as of 2010-02-03

Line 
1Check the return value of function calls.
2
3From: Erik Hovland <erik@hovland.org>
4
5The member function readStringList returns status. It probably should
6be checked.
7---
8
9 mythtv/libs/libmythdb/remotefile.cpp |   29 +++++++++++++++++++++++------
10 1 files changed, 23 insertions(+), 6 deletions(-)
11
12
13diff --git a/mythtv/libs/libmythdb/remotefile.cpp b/mythtv/libs/libmythdb/remotefile.cpp
14index f34c1e6..0479034 100644
15--- a/mythtv/libs/libmythdb/remotefile.cpp
16+++ b/mythtv/libs/libmythdb/remotefile.cpp
17@@ -95,7 +95,14 @@ MythSocket *RemoteFile::openSocket(bool control)
18     {
19         strlist.append( QString("ANN Playback %1 %2").arg(hostname).arg(false) );
20         lsock->writeStringList(strlist);
21-        lsock->readStringList(strlist, true);
22+        if (!lsock->readStringList(strlist, true))
23+        {
24+            VERBOSE(VB_IMPORTANT, loc_err +
25+                    QString("\n\t\t\tCould not read string list from server "
26+                            "%1:%2").arg(host).arg(port));
27+            lsock->DownRef();
28+            return NULL;
29+        }
30     }
31     else
32     {
33@@ -108,8 +115,16 @@ MythSocket *RemoteFile::openSocket(bool control)
34         for (; it != possibleauxfiles.end(); ++it)
35             strlist << *it;
36 
37-        lsock->writeStringList(strlist);
38-        lsock->readStringList(strlist, true);
39+        if (!lsock->writeStringList(strlist) ||
40+            !lsock->readStringList(strlist, true))
41+        {
42+            VERBOSE(VB_IMPORTANT, loc_err +
43+                    QString("Did not get proper response from %1:%2")
44+                    .arg(host).arg(port));
45+            strlist.clear();
46+            strlist.push_back("ERROR");
47+            strlist.push_back("invalid response");
48+        }
49 
50         if (strlist.size() >= 4)
51         {
52@@ -468,9 +483,11 @@ int RemoteFile::Write(const void *data, int size)
53 
54         if (controlSock->bytesAvailable() > 0)
55         {
56-            controlSock->readStringList(strlist, true);
57-            recv = strlist[0].toInt(); // -1 on backend error
58-            response = true;
59+            if (controlSock->readStringList(strlist, true))
60+            {
61+                recv = strlist[0].toInt(); // -1 on backend error
62+                response = true;
63+            }
64         }
65     }
66