]> git.sesse.net Git - nageru/blobdiff - futatabi/main.cpp
Fix a follow-up error introduced when fixing a Coverity Scan issue.
[nageru] / futatabi / main.cpp
index c4b31f55c231ed86b1d6ab61f5792e9ecfa81193..edff307e38bd1a98584ef3c0a94d1e176f192538 100644 (file)
@@ -200,13 +200,11 @@ int main(int argc, char **argv)
 
        string frame_dir = global_flags.working_directory + "/frames";
 
-       struct stat st;
-       if (stat(frame_dir.c_str(), &st) == -1) {
+       if (mkdir(frame_dir.c_str(), 0777) == 0) {
                fprintf(stderr, "%s does not exist, creating it.\n", frame_dir.c_str());
-               if (mkdir(frame_dir.c_str(), 0777) == -1) {
-                       perror(global_flags.working_directory.c_str());
-                       exit(1);
-               }
+       } else if (errno != EEXIST) {
+               perror(global_flags.working_directory.c_str());
+               exit(1);
        }
 
        avformat_network_init();
@@ -240,7 +238,10 @@ int main(int argc, char **argv)
        {
                QSurface *surface = create_surface();
                QOpenGLContext *context = create_context(surface);
-               make_current(context, surface);
+               if (!make_current(context, surface)) {
+                       printf("oops\n");
+                       exit(1);
+               }
                CHECK(movit::init_movit(MOVIT_SHADER_DIR, movit::MOVIT_DEBUG_OFF));
                delete_context(context);
                // TODO: Delete the surface, too.
@@ -279,7 +280,7 @@ void load_frame_file(const char *filename, const string &basename, unsigned file
        if (!all_frames.empty()) {
                // We already had this cached in the database, so no need to look in the file.
                for (const DB::FrameOnDiskAndStreamIdx &frame : all_frames) {
-                       if (frame.stream_idx >= 0 && frame.stream_idx < MAX_STREAMS) {
+                       if (frame.stream_idx < MAX_STREAMS) {
                                frames[frame.stream_idx].push_back(frame.frame);
                                start_pts = max(start_pts, frame.frame.pts);
                        }
@@ -341,6 +342,10 @@ void load_frame_file(const char *filename, const string &basename, unsigned file
                FrameOnDisk frame;
                frame.pts = hdr.pts();
                frame.offset = ftell(fp);
+               if (frame.offset == -1) {
+                       fprintf(stderr, "WARNING: %s: ftell() failed (%s).\n", filename, strerror(errno));
+                       break;
+               }
                frame.filename_idx = filename_idx;
                frame.size = hdr.file_size();
 
@@ -361,9 +366,14 @@ void load_frame_file(const char *filename, const string &basename, unsigned file
                        filename, skipped_bytes);
        }
 
-       size_t size = ftell(fp);
+       off_t size = ftell(fp);
        fclose(fp);
 
+       if (size == -1) {
+               fprintf(stderr, "WARNING: %s: ftell() failed (%s).\n", filename, strerror(errno));
+               return;
+       }
+
        db->store_frame_file(basename, size, all_frames);
 }
 
@@ -431,6 +441,7 @@ void load_existing_frames()
                // Add a gap of one second from the old frames to the new ones.
                start_pts += TIMEBASE;
        }
+       current_pts = start_pts;
 
        for (int stream_idx = 0; stream_idx < MAX_STREAMS; ++stream_idx) {
                sort(frames[stream_idx].begin(), frames[stream_idx].end(),
@@ -486,15 +497,7 @@ int record_thread_func()
                        FrameOnDisk frame = write_frame(pkt.stream_index, pts, pkt.data, pkt.size, &db);
 
                        post_to_main_thread([pkt, frame] {
-                               if (pkt.stream_index == 0) {
-                                       global_mainwindow->ui->input1_display->setFrame(pkt.stream_index, frame);
-                               } else if (pkt.stream_index == 1) {
-                                       global_mainwindow->ui->input2_display->setFrame(pkt.stream_index, frame);
-                               } else if (pkt.stream_index == 2) {
-                                       global_mainwindow->ui->input3_display->setFrame(pkt.stream_index, frame);
-                               } else if (pkt.stream_index == 3) {
-                                       global_mainwindow->ui->input4_display->setFrame(pkt.stream_index, frame);
-                               }
+                               global_mainwindow->display_frame(pkt.stream_index, frame);
                        });
 
                        if (last_pts != -1 && global_flags.slow_down_input) {