1 | Pointer checking in MSocketDevice::readData |
---|
2 | |
---|
3 | From: Erik Hovland <erik@hovland.org> |
---|
4 | |
---|
5 | Much like the fix in writeData, it is not necessary to do anything but |
---|
6 | return 0 if the read length given is zero. This provides a fast path if |
---|
7 | users actually want to use the member function that way. |
---|
8 | |
---|
9 | Then the conditional for checking the pointer to the data to read can |
---|
10 | be checked for validity w/out the need to check length. |
---|
11 | |
---|
12 | Since my writeData patch ended up in the _win version as well, I am |
---|
13 | submitting this patch w/ the same change to _win (although it is |
---|
14 | untested 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 | |
---|
22 | diff --git a/mythtv/libs/libmythdb/msocketdevice_unix.cpp b/mythtv/libs/libmythdb/msocketdevice_unix.cpp |
---|
23 | index 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, |
---|
41 | diff --git a/mythtv/libs/libmythdb/msocketdevice_win.cpp b/mythtv/libs/libmythdb/msocketdevice_win.cpp |
---|
42 | index 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) |
---|