Fix some coverity-reported stuff.
authorCarl Hetherington <cth@carlh.net>
Wed, 5 Feb 2014 14:52:23 +0000 (14:52 +0000)
committerCarl Hetherington <cth@carlh.net>
Wed, 5 Feb 2014 14:52:23 +0000 (14:52 +0000)
13 files changed:
ChangeLog
src/lib/audio_analysis.cc
src/lib/config.h
src/lib/ffmpeg.cc
src/lib/ffmpeg_content.h
src/lib/player.cc
src/lib/scp_dcp_job.cc
src/lib/writer.cc
src/tools/dcpomatic_create.cc
src/tools/server_test.cc
src/wx/audio_plot.cc
src/wx/timeline.cc
test/resampler_test.cc

index d788d63cdbc6cb11bc839d76aab4005c6a36bff6..28e29b88daabc124ec9829de1833c63203d6432a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2014-02-05  Carl Hetherington  <cth@carlh.net>
 
+       * A variety of fixes to small problems found by Coverity.
+
        * Updates to it_IT translation from William Fanelli.
 
 2014-02-02  Carl Hetherington  <cth@carlh.net>
index 1488f89fcfdfb6f2ac32aaed158e36e1a9eb589d..98d092726c9487f8152a97b6965bd4ff3219df4e 100644 (file)
@@ -93,10 +93,21 @@ AudioAnalysis::AudioAnalysis (boost::filesystem::path filename)
        for (int i = 0; i < channels; ++i) {
                int points;
                fscanf (f, "%d", &points);
+               if (feof (f)) {
+                       fclose (f);
+                       return;
+               }
+               
                for (int j = 0; j < points; ++j) {
                        _data[i].push_back (AudioPoint (f));
+                       if (feof (f)) {
+                               fclose (f);
+                               return;
+                       }
                }
        }
+
+       fclose (f);
 }
 
 void
index 791e41e8f6f27a14b5626e492fc714c824da027f..d77969b3e9e14956f6e0a043576077ea2eba924d 100644 (file)
@@ -193,14 +193,6 @@ public:
                _server_port_base = p;
        }
 
-       void set_reference_scaler (Scaler const * s) {
-               _reference_scaler = s;
-       }
-       
-       void set_reference_filters (std::vector<Filter const *> const & f) {
-               _reference_filters = f;
-       }
-
        /** @param i IP address of a TMS that we can copy DCPs to */
        void set_tms_ip (std::string i) {
                _tms_ip = i;
@@ -326,10 +318,6 @@ private:
        bool _use_any_servers;
        /** J2K encoding servers that should definitely be used */
        std::vector<std::string> _servers;
-       /** Scaler to use for the "A" part of A/B comparisons */
-       Scaler const * _reference_scaler;
-       /** Filters to use for the "A" part of A/B comparisons */
-       std::vector<Filter const *> _reference_filters;
        /** The IP address of a TMS that we can copy DCPs to */
        std::string _tms_ip;
        /** The path on a TMS that we should write DCPs to */
index d3653e311fdfadeabe97d9a3898d5fe0c835fb36..b7ae04b069017d8404325939fdbbad8ba4108f26 100644 (file)
@@ -146,7 +146,8 @@ void
 FFmpeg::setup_video ()
 {
        boost::mutex::scoped_lock lm (_mutex);
-       
+
+       assert (_video_stream >= 0);
        AVCodecContext* context = _format_context->streams[_video_stream]->codec;
        AVCodec* codec = avcodec_find_decoder (context->codec_id);
 
index 7ff159b852b4cb69df4004b1f6a813ad2131e182..b1f2abceaa37d46a382a2e2607dcf45e930b6291 100644 (file)
@@ -86,6 +86,8 @@ private:
        /* Constructor for tests */
        FFmpegAudioStream ()
                : FFmpegStream ("", 0)
+               , frame_rate (0)
+               , channels (0)
                , mapping (1)
        {}
 };
index e661a7b3693930eac8b0348fd250de185a098706..42551889b03563f2dbea0f8e779ddbcddfdd767e 100644 (file)
@@ -62,6 +62,8 @@ public:
                , decoder (d)
                , video_position (c->position ())
                , audio_position (c->position ())
+               , repeat_to_do (0)
+               , repeat_done (0)
        {}
 
        /** Set this piece to repeat a video frame a given number of times */
index 310303c09c54d371dc5c6589c9eb85e755f5c89a..22715978a7040ba279843c8e2ab0488a8f98f7a3 100644 (file)
@@ -191,8 +191,10 @@ SCPDCPJob::run ()
                        }
                        to_do -= t;
                        bytes_transferred += t;
-                       
-                       set_progress ((double) bytes_transferred / bytes_to_transfer);
+
+                       if (bytes_to_transfer > 0) {
+                               set_progress ((double) bytes_transferred / bytes_to_transfer);
+                       }
                }
 
                fclose (f);
index c2a6c981bc8f31a2629affe444df88c225ae7ddc..42187dc6e78616a24673057bb4e9eb87802381aa 100644 (file)
@@ -541,7 +541,9 @@ Writer::check_existing_picture_mxf ()
                shared_ptr<Job> job = _job.lock ();
                assert (job);
 
-               job->set_progress (float (_first_nonexistant_frame) / N);
+               if (N > 0) {
+                       job->set_progress (float (_first_nonexistant_frame) / N);
+               }
 
                if (_film->three_d ()) {
                        if (!check_existing_picture_mxf_frame (mxf, _first_nonexistant_frame, EYES_LEFT)) {
index 8be468b306332de52aa15511c606680201c7abc1..8dc4de50ef278dc66a02b9964a9fd146607086a9 100644 (file)
@@ -20,6 +20,7 @@
 #include <string>
 #include <iostream>
 #include <cstdlib>
+#include <stdexcept>
 #include <getopt.h>
 #include <boost/filesystem.hpp>
 #include "lib/version.h"
@@ -34,6 +35,7 @@ using std::string;
 using std::cout;
 using std::cerr;
 using std::list;
+using std::exception;
 using boost::shared_ptr;
 
 static void
@@ -98,31 +100,37 @@ main (int argc, char* argv[])
        dcpomatic_setup ();
        ui_signaller = new UISignaller ();
 
-       shared_ptr<Film> film (new Film (output));
-       if (!name.empty ()) {
-               film->set_name (name);
-       }
-
-       for (int i = optind; i < argc; ++i) {
-               film->examine_and_add_content (content_factory (film, argv[i]));
-       }
-
-       JobManager* jm = JobManager::instance ();
-       while (jm->work_to_do ()) {
-               ui_signaller->ui_idle ();
-       }
-
-       if (jm->errors ()) {
-               list<shared_ptr<Job> > jobs = jm->get ();
-               for (list<shared_ptr<Job> >::iterator i = jobs.begin(); i != jobs.end(); ++i) {
-                       if ((*i)->finished_in_error ()) {
-                               cerr << (*i)->error_summary () << "\n"
-                                    << (*i)->error_details () << "\n";
+       try {
+               shared_ptr<Film> film (new Film (output));
+               if (!name.empty ()) {
+                       film->set_name (name);
+               }
+               
+               for (int i = optind; i < argc; ++i) {
+                       film->examine_and_add_content (content_factory (film, argv[i]));
+               }
+               
+               JobManager* jm = JobManager::instance ();
+               while (jm->work_to_do ()) {
+                       ui_signaller->ui_idle ();
+               }
+               
+               if (jm->errors ()) {
+                       list<shared_ptr<Job> > jobs = jm->get ();
+                       for (list<shared_ptr<Job> >::iterator i = jobs.begin(); i != jobs.end(); ++i) {
+                               if ((*i)->finished_in_error ()) {
+                                       cerr << (*i)->error_summary () << "\n"
+                                            << (*i)->error_details () << "\n";
+                               }
                        }
+                       exit (EXIT_FAILURE);
                }
+               
+               film->write_metadata ();
+       } catch (exception& e) {
+               cerr << argv[0] << ": " << e.what() << "\n";
                exit (EXIT_FAILURE);
        }
-
-       film->write_metadata ();
+               
        return 0;
 }
index b2c5e784ba8caf2346c08b903c5a81dec8d8e296..039088862ef8bf7801af1d76da482ff85c425373 100644 (file)
@@ -137,14 +137,14 @@ main (int argc, char* argv[])
 
        dcpomatic_setup ();
 
-       server = new ServerDescription (server_host, 1);
-       film.reset (new Film (film_dir));
-       film->read_metadata ();
-
-       shared_ptr<Player> player = film->make_player ();
-       player->disable_audio ();
-
        try {
+               server = new ServerDescription (server_host, 1);
+               film.reset (new Film (film_dir));
+               film->read_metadata ();
+               
+               shared_ptr<Player> player = film->make_player ();
+               player->disable_audio ();
+
                player->Video.connect (boost::bind (process_video, _1, _2, _3, _5));
                bool done = false;
                while (!done) {
index f78885772ce033e682a1e9d178d85c93441b2b45..fd261925518b3c058605bf4f04951895e073ec2f 100644 (file)
@@ -259,7 +259,9 @@ AudioPlot::plot_rms (wxGraphicsPath& path, int channel) const
                        p += pow (*j, 2);
                }
 
-               p = sqrt (p / smoothing.size ());
+               if (smoothing.size() > 0) {
+                       p = sqrt (p / smoothing.size ());
+               }
 
                path.AddLineToPoint (_db_label_width + i * _x_scale, y_for_linear (p));
        }
index 6cc1f79d93dd23c9d0b089648f36edcf1892c893..4e306c4998a526081e4629f79c03ba5d4fcaa63d 100644 (file)
@@ -474,7 +474,7 @@ void
 Timeline::setup_pixels_per_time_unit ()
 {
        shared_ptr<const Film> film = _film.lock ();
-       if (!film) {
+       if (!film || film->length() == 0) {
                return;
        }
 
index 1ef69b0c26bbb71f0851b15808c0ce1482ad0d9b..9247159a7065b1a46ecf06d49f74f8cfdbab6695 100644 (file)
@@ -33,7 +33,7 @@ resampler_test_one (int from, int to)
        int total_out = 0;
 
        /* 3 hours */
-       int64_t const N = from * 60 * 60 * 3;
+       int64_t const N = int64_t (from) * 60 * 60 * 3;
        
        for (int64_t i = 0; i < N; i += 1000) {
                shared_ptr<AudioBuffers> a (new AudioBuffers (1, 1000));