Ticket #6998: libs_libmythdb-pointer-checks

File libs_libmythdb-pointer-checks, 2.0 KB (added by Erik Hovland <erik@…>, 15 years ago)

Check ::readData like ::writeData.

Line 
1Pointer checking in MSocketDevice::readData
2
3From: Erik Hovland <erik@hovland.org>
4
5Much like the fix in writeData, it is not necessary to do anything but
6return 0 if the read length given is zero. This provides a fast path if
7users actually want to use the member function that way.
8
9Then the conditional for checking the pointer to the data to read can
10be checked for validity w/out the need to check length.
11
12Since my writeData patch ended up in the _win version as well, I am
13submitting this patch w/ the same change to _win (although it is
14untested by me).
15---
16
17 mythtv/libs/libmythdb/msocketdevice_unix.cpp |    6 +++++-
18 mythtv/libs/libmythdb/msocketdevice_win.cpp  |    6 +++++-
19 2 files changed, 10 insertions(+), 2 deletions(-)
20
21
22diff --git a/mythtv/libs/libmythdb/msocketdevice_unix.cpp b/mythtv/libs/libmythdb/msocketdevice_unix.cpp
23index d969fa5..4353c7e 100644
24--- a/mythtv/libs/libmythdb/msocketdevice_unix.cpp
25+++ b/mythtv/libs/libmythdb/msocketdevice_unix.cpp
26@@ -734,9 +734,13 @@ qint64 MSocketDevice::waitForMore( int msecs, bool *timeout ) const
27 */
28 qint64 MSocketDevice::readData( char *data, qint64 maxlen )
29 {
30-    if ( data == 0 && maxlen != 0 ) {
31+    if ( maxlen == 0 )
32+        return 0;
33+
34+    if ( data == 0 ) {
35         VERBOSE(VB_SOCKET|VB_EXTRA,
36                 "MSocketDevice::readBlock: Null pointer error");
37+        return -1;
38     }
39     if ( !isValid() ) {
40         VERBOSE(VB_SOCKET|VB_EXTRA,
41diff --git a/mythtv/libs/libmythdb/msocketdevice_win.cpp b/mythtv/libs/libmythdb/msocketdevice_win.cpp
42index 28a71cf..0f516e2 100644
43--- a/mythtv/libs/libmythdb/msocketdevice_win.cpp
44+++ b/mythtv/libs/libmythdb/msocketdevice_win.cpp
45@@ -691,9 +691,13 @@ qint64 MSocketDevice::waitForMore( int msecs, bool *timeout ) const
46 
47 qint64 MSocketDevice::readData( char *data, qint64 maxlen )
48 {
49+    if ( maxlen == 0 )
50+        return 0;
51+
52 #if defined(QT_CHECK_NULL)
53-    if ( data == 0 && maxlen != 0 ) {
54+    if ( data == 0 ) {
55        qWarning( "MSocketDevice::readBlock: Null pointer error" );
56+        return -1;
57     }
58 #endif
59 #if defined(QT_CHECK_STATE)