Check the return value for null or check the pointer for null before

From: Erik Hovland <erik@hovland.org>

dereferencing.
---

 libs/libmythtv/NuppelVideoRecorder.cpp |    7 +++++++
 libs/libmythtv/avformatdecoder.cpp     |   19 +++++++++++--------
 libs/libmythtv/fifowriter.cpp          |    3 ++-
 libs/libmythtv/osdimagecache.cpp       |    8 +++++++-
 libs/libmythtv/viewschdiff.cpp         |    5 +++++
 libs/libmythtv/xine_demux_sputext.c    |    2 ++
 6 files changed, 34 insertions(+), 10 deletions(-)

diff --git a/libs/libmythtv/NuppelVideoRecorder.cpp b/libs/libmythtv/NuppelVideoRecorder.cpp
index d24e38a..b599847 100644
--- a/libs/libmythtv/NuppelVideoRecorder.cpp
+++ b/libs/libmythtv/NuppelVideoRecorder.cpp
@@ -3081,6 +3081,13 @@ void NuppelVideoRecorder::WriteVideo(VideoFrame *frame, bool skipsync,
             QMutexLocker locker(&avcodeclock);
             tmp = avcodec_encode_video(mpa_vidctx, (unsigned char *)strm, 
                                        len, &mpa_picture); 
+            if (tmp == -1)
+            {
+                VERBOSE(VB_IMPORTANT,
+                        LOC_ERR + "NuppelVideoRecorder::WriteVideo : "
+                                  "avcodec_encode_video() failed");
+                return;
+            }
         }
     }
     else
diff --git a/libs/libmythtv/avformatdecoder.cpp b/libs/libmythtv/avformatdecoder.cpp
index 1315686..e7b4735 100644
--- a/libs/libmythtv/avformatdecoder.cpp
+++ b/libs/libmythtv/avformatdecoder.cpp
@@ -1373,7 +1373,7 @@ void AvFormatDecoder::ScanTeletextCaptions(int av_index)
  */
 void AvFormatDecoder::ScanDSMCCStreams(void)
 {
-    if (!ic->cur_pmt_sect)
+    if (!ic || !ic->cur_pmt_sect)
         return;
 
     if (!itv && ! (itv = GetNVP()->GetInteractiveTV()))
@@ -3541,13 +3541,16 @@ bool AvFormatDecoder::GetFrame(int onlyvideo)
                     if (!allowedquit && (onlyvideo < 0))
                     {
                         uint fill, total;
-                        GetNVP()->GetAudioBufferStatus(fill, total);
-                        total /= 6; // HACK needed for some audio files
-                        allowedquit =
-                            (fill == 0) || (fill > (total>>1)) ||
-                            ((total - fill) < (uint) data_size) ||
-                            (ofill + total_decoded_audio > (total>>2)) ||
-                            ((total - fill) < (uint) data_size * 2);
+                        if (GetNVP()->GetAudioBufferStatus(fill, total)) {
+                            total /= 6; // HACK needed for some audio files
+                            allowedquit =
+                                (fill == 0) || (fill > (total>>1)) ||
+                                ((total - fill) < (uint) data_size) ||
+                                (ofill + total_decoded_audio > (total>>2)) ||
+                                ((total - fill) < (uint) data_size * 2);
+                        } else
+                            VERBOSE(VB_IMPORTANT, LOC_ERR + "AvFormatDecoder::GetFrame : "
+                                    "Failed topping off buffers in audio only mode");
                     }
 
                     break;
diff --git a/libs/libmythtv/fifowriter.cpp b/libs/libmythtv/fifowriter.cpp
index 15addc2..38d0d42 100644
--- a/libs/libmythtv/fifowriter.cpp
+++ b/libs/libmythtv/fifowriter.cpp
@@ -142,7 +142,8 @@ void FIFOWriter::FIFOWriteThread(void)
             break;
         if (fd == -1)
             fd = open(filename[id].ascii(), O_WRONLY| O_SYNC);
-        write(fd, fb_outptr[id]->data, fb_outptr[id]->blksize);
+        if (fd >= 0)
+            write(fd, fb_outptr[id]->data, fb_outptr[id]->blksize);
         pthread_mutex_lock(&fifo_lock[id]);
         fb_outptr[id] = fb_outptr[id]->next;
         pthread_cond_signal(&full_cond[id]);
diff --git a/libs/libmythtv/osdimagecache.cpp b/libs/libmythtv/osdimagecache.cpp
index a3f986a..d5be817 100644
--- a/libs/libmythtv/osdimagecache.cpp
+++ b/libs/libmythtv/osdimagecache.cpp
@@ -172,7 +172,13 @@ OSDImageCacheValue *OSDImageCache::Get(const QString &key, bool useFile)
 
     QDir dir(MythContext::GetConfDir() + "/osdcache/");
     QFile cacheFile(dir.path() + "/" + key);
-    cacheFile.open(QIODevice::ReadOnly);
+    if (!cacheFile.open(QIODevice::IO_ReadOnly))
+    {
+        VERBOSE(VB_IMPORTANT,
+                LOC_ERR + key + " Failed opening read-only cache file");
+        return NULL;
+    }
+
     uint32_t imwidth  = 0;
     uint32_t imheight = 0;
 
diff --git a/libs/libmythtv/viewschdiff.cpp b/libs/libmythtv/viewschdiff.cpp
index e618e66..c321299 100644
--- a/libs/libmythtv/viewschdiff.cpp
+++ b/libs/libmythtv/viewschdiff.cpp
@@ -201,6 +201,9 @@ void ViewScheduleDiff::updateBackground(void)
     QPainter tmp(&bground);
 
     LayerSet *container = theme->GetSet("background");
+    if (!container)
+        return;
+
     container->Draw(&tmp, 0, 0);
 
     tmp.end();
@@ -263,6 +266,8 @@ void ViewScheduleDiff::edit()
 void ViewScheduleDiff::upcoming()
 {
     ProgramInfo *pi = CurrentProgram();
+    if (!pi)
+        return;
 
     ProgLister *pl = new ProgLister(plTitle, pi->title, "",
                                    gContext->GetMainWindow(), "proglist");
diff --git a/libs/libmythtv/xine_demux_sputext.c b/libs/libmythtv/xine_demux_sputext.c
index b4bdb23..5ca78fc 100644
--- a/libs/libmythtv/xine_demux_sputext.c
+++ b/libs/libmythtv/xine_demux_sputext.c
@@ -523,6 +523,8 @@ static subtitle_t *sub_read_line_ssa(demux_sputext_t *this,subtitle_t *current)
 		   line3) < 9	    );
   
   line2=strchr(line3, ',');
+  if (!line2)
+    return NULL;
   
   for (comma = 4; comma < max_comma; comma ++)
     {
