Ticket #5515: libs_libmythtv-forward-null.patch

File libs_libmythtv-forward-null.patch, 6.1 KB (added by Erik Hovland <erik@…>, 13 years ago)

checks pointers before dereference of said pointer

  • mythtv/libs/libmythtv/NuppelVideoPlayer.cpp

    Fix any instance where null is checked (or tracked) in
    
    From: Erik Hovland <erik@hovland.org>
    
    a function once and not checked every time the pointer
    is used.
    ---
    
     mythtv/libs/libmythtv/NuppelVideoPlayer.cpp |   42 ++++++++++++++++-----------
     mythtv/libs/libmythtv/tv_play.cpp           |   20 +++++++++----
     2 files changed, 39 insertions(+), 23 deletions(-)
    
    diff --git a/mythtv/libs/libmythtv/NuppelVideoPlayer.cpp b/mythtv/libs/libmythtv/NuppelVideoPlayer.cpp
    index 27e223d..33f053e 100644
    a b void NuppelVideoPlayer::InitAVSync(void) 
    22632263        warpfactor = warpfactor_avg;
    22642264    }
    22652265
    2266     refreshrate = videoOutput->GetRefreshRate();
     2266    refreshrate = videoOutput ? videoOutput->GetRefreshRate() : -1;
    22672267    if (refreshrate <= 0)
    22682268        refreshrate = frame_interval;
     2269
    22692270    vsynctol = refreshrate / 4;
    22702271
    22712272    if (!using_null_videoout)
    void NuppelVideoPlayer::OutputVideoLoop(void) 
    28482849
    28492850        if (ringBuffer->isDVD())
    28502851        {
    2851             int nbframes = videoOutput->ValidVideoFrames();
     2852            int nbframes = 0;
     2853            if (videoOutput)
     2854                nbframes = videoOutput->ValidVideoFrames();
    28522855
    28532856            if (nbframes < 2)
    28542857            {
    void NuppelVideoPlayer::DoPlay(void) 
    41174120    if (skip_changed)
    41184121    {
    41194122        //cout << "handling skip change" << endl;
    4120         videoOutput->SetPrebuffering(ffrew_skip == 1);
     4123        if (videoOutput) {
     4124            videoOutput->SetPrebuffering(ffrew_skip == 1);
    41214125
    41224126#ifdef USING_IVTV
    4123         if (IsIVTVDecoder())
    4124         {
    4125             VideoOutputIvtv *vidout = (VideoOutputIvtv *)videoOutput;
    4126             vidout->NextPlay(play_speed / ffrew_skip, normal_speed,
    4127                              (ffrew_skip == 1) ? 2 : 0);
    4128         }
     4127            if (IsIVTVDecoder())
     4128            {
     4129                VideoOutputIvtv *vidout = dynamic_cast<VideoOutputIvtv *>(videoOutput);
     4130                if (vidout)
     4131                    vidout->NextPlay(play_speed / ffrew_skip, normal_speed,
     4132                                     (ffrew_skip == 1) ? 2 : 0);
     4133            }
    41294134#endif
     4135        }
    41304136
    41314137        GetDecoder()->setExactSeeks(exactseeks && ffrew_skip == 1);
    41324138        GetDecoder()->DoRewind(framesPlayed);
    void NuppelVideoPlayer::DoPlay(void) 
    41724178    }
    41734179
    41744180#ifdef USING_IVTV
    4175     if (IsIVTVDecoder())
     4181    if (IsIVTVDecoder() && videoOutput)
    41764182    {
    4177         VideoOutputIvtv *vidout = (VideoOutputIvtv *)videoOutput;
    4178         vidout->Play(play_speed / ffrew_skip, normal_speed,
    4179                      (ffrew_skip == 1) ? 2 : 0);
     4183        VideoOutputIvtv *vidout = dynamic_cast<VideoOutputIvtv *>(videoOutput);
     4184        if (vidout)
     4185            vidout->Play(play_speed / ffrew_skip, normal_speed,
     4186                         (ffrew_skip == 1) ? 2 : 0);
    41804187    }
    41814188#endif
    41824189
    long long NuppelVideoPlayer::CalcMaxFFTime(long long ff, bool setjump) const 
    42854292            if (behind < maxtime || behind - ff <= maxtime * 2)
    42864293            {
    42874294                ret = -1;
    4288                 if (setjump)
     4295                if (setjump && livetvchain)
    42894296                    livetvchain->JumpToNext(true, 1);
    42904297            }
    42914298        }
    bool NuppelVideoPlayer::IsReallyNearEnd(void) const 
    43664373 */
    43674374bool NuppelVideoPlayer::IsNearEnd(long long margin) const
    43684375{
    4369     long long framesRead, framesLeft;
     4376    long long framesRead, framesLeft = 0;
    43704377
    43714378    if (!m_playbackinfo || m_playbackinfo->isVideo || !GetDecoder())
    43724379        return false;
    bool NuppelVideoPlayer::IsNearEnd(long long margin) const 
    44024409    if (livetv && livetvchain && livetvchain->HasNext())
    44034410        return false;
    44044411
    4405     framesLeft = nvr_enc->GetCachedFramesWritten() - framesRead;
     4412    if (nvr_enc)
     4413        framesLeft = nvr_enc->GetCachedFramesWritten() - framesRead;
    44064414
    44074415    // if it looks like we are near end, get an updated GetFramesWritten()
    4408     if (framesLeft < margin)
     4416    if (framesLeft < margin && nvr_enc)
    44094417        framesLeft = nvr_enc->GetFramesWritten() - framesRead;
    44104418
    44114419    return (framesLeft < margin);
  • mythtv/libs/libmythtv/tv_play.cpp

    diff --git a/mythtv/libs/libmythtv/tv_play.cpp b/mythtv/libs/libmythtv/tv_play.cpp
    index 588002b..0a80b3e 100644
    a b void TV::SwapPIP(void) 
    40334033    main.buffer   = prbuffer;
    40344034    main.recorder = recorder;
    40354035    main.chain    = tvchain;
    4036     main.frame    = nvp->GetFramesPlayed();
     4036    main.frame    = nvp ? nvp->GetFramesPlayed() : -1;
    40374037    pip.buffer    = piprbuffer;
    40384038    pip.recorder  = piprecorder;
    40394039    pip.chain     = piptvchain;
    void TV::SwapPIP(void) 
    40454045    piprbuffer->Pause();
    40464046    piprbuffer->WaitForPause();
    40474047
    4048     nvp->StopPlaying();
     4048    if (nvp)
     4049        nvp->StopPlaying();
     4050
    40494051    pipnvp->StopPlaying();
     4052
    40504053    {
    40514054        QMutexLocker locker(&osdlock); // prevent UpdateOSDSignal using osd...
    40524055        pthread_join(decode, NULL);
    void TV::DoPause(bool showOSD) 
    41954198
    41964199    if (paused)
    41974200    {
    4198         activerbuffer->WaitForPause();
     4201        if (activerbuffer)
     4202            activerbuffer->WaitForPause();
     4203
    41994204        DoNVPSeek(time);
    42004205        if (showOSD)
    42014206            UpdateOSDSeekMessage(tr("Paused"), -1);
    void TV::ChangeChannel(uint chanid, const QString &chan) 
    51015106    if (!prevChan.empty() && prevChan.back() == channum)
    51025107        return;
    51035108
    5104     if (!activerecorder->CheckChannel(channum))
     5109    if (!activerecorder || !activerecorder->CheckChannel(channum))
    51055110        return;
    51065111
    51075112    if (nvp)
    bool TV::VideoThemeCheck(QString str, bool stayPaused) 
    58425847    bool ret = true;
    58435848    bool allowembed = (nvp && nvp->getVideoOutput() &&
    58445849                    nvp->getVideoOutput()->AllowPreviewEPG());
     5850    long long margin = 0;
     5851
     5852    if (nvp)
     5853        margin = static_cast<long long>((nvp->GetFrameRate() *
     5854                                        nvp->GetAudioStretchFactor()));
    58455855
    5846     long long margin = (long long)(nvp->GetFrameRate() *
    5847                         nvp->GetAudioStretchFactor());
    58485856    margin = margin * 5;
    58495857    QDomElement xmldata;
    58505858    XMLParse *theme = new XMLParse();