Back to success stories

Sample of Defect

Project Name CID Checker Category Developer Description
ScummVM 1308097 USELESS_CALL Incorrect expression An extremely nice thing which was discovered only by Coverity. We have 2 class methods: clear() which clears the surface and empty() which checks whether the surface is 0 size. Native English speaker wanted to fill the screen with 0. He used incorrect call screen.empty(). Coverity gave a warning about a useless call, which let us catch this bug with much ease. Otherwise, we were seeing weird behaviour, while the code inspection was showing: here is screen emptying, proceed!
File: /engines/sherlock/tattoo/tattoo_journal.cpp
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
}

void TattooJournal::show() {
        Events &events = *_vm->_events;
        Resources &res = *_vm->_res;
        Screen &screen = *_vm->_screen;
        TattooUserInterface &ui = *(TattooUserInterface *)_vm->_ui;
        byte palette[PALETTE_SIZE];
        
        Common::Point oldScroll = screen._currentScroll;
        screen._currentScroll = Common::Point(0, 0);

        // Load journal images
        _journalImages = new ImageFile("journal.vgs");

        // Load palette
        Common::SeekableReadStream *stream = res.load("journal.pal");
        stream->read(palette, PALETTE_SIZE);
        ui.setupBGArea(palette);
        screen.translatePalette(palette);
        delete stream;

        // Set screen to black, and set background
        screen._backBuffer1.SHblitFrom((*_journalImages)[0], Common::Point(0, 0));
 <<< CID 1308097: Incorrect expression USELESS_CALL
 <<< Calling "screen->empty()" is only useful for its return value, which is ignored.
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
        screen.empty();
        screen.setPalette(palette);

        if (_journal.empty()) {
                _up = _down = false;
        } else {
                drawJournal(0, 0);
        }
        drawControls(0);
        screen.slamRect(Common::Rect(0, 0, SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT));

        _exitJournal = false;
        _scrollingTimer = 0;

        do {
                events.pollEventsAndWait();
                events.setButtonState();
                _wait = true;

                handleKeyboardEvents();
                highlightJournalControls(true);
                
                handleButtons();

                if (_wait)
                        events.wait(2);
                
Events:
side_effect_free tattoo_journal.cpp:69