diff options
author | 2017-03-10 18:02:44 +0300 | |
---|---|---|
committer | 2017-03-11 02:21:54 +0300 | |
commit | 58f2def8621f0fb8472f210edf31635314ecc1d4 (patch) | |
tree | 067b7cb968cdca1a25a5bcf42eddc59a645be64f /src | |
parent | 6b5e155c0dd99fd618760c2457a541a904e1bec3 (diff) |
formats/cbm_tap: fix CID: 138003 "Dereference before null check"
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/formats/cbm_tap.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/lib/formats/cbm_tap.cpp b/src/lib/formats/cbm_tap.cpp index 0b0950eebcc..2699ab51ec0 100644 --- a/src/lib/formats/cbm_tap.cpp +++ b/src/lib/formats/cbm_tap.cpp @@ -173,9 +173,7 @@ static int cbm_tap_do_work( int16_t **buffer, int length, const uint8_t *data ) int i, j = 0; int size = 0; - int version = data[0x0c]; - int system = data[0x0d]; - int video_standard = data[0x0e]; + int version, system, video_standard; int tap_frequency = 0; int byte_samples = 0; @@ -186,6 +184,14 @@ static int cbm_tap_do_work( int16_t **buffer, int length, const uint8_t *data ) in Commodore tapes. Implementation here would follow */ /* int waveamp_high, waveamp_low; */ + /* is the .tap file corrupted? */ + if ((data == nullptr) || (length <= CBM_HEADER_SIZE)) + return -1; + + version = data[0x0c]; + system = data[0x0d]; + video_standard = data[0x0e]; + /* Log .TAP info but only once */ if (!(buffer == nullptr)) { @@ -203,10 +209,6 @@ static int cbm_tap_do_work( int16_t **buffer, int length, const uint8_t *data ) return -1; } - /* is the .tap file corrupted? */ - if ((data == nullptr) || (length <= CBM_HEADER_SIZE)) - return -1; - /* read the frequency from the .tap header */ switch (system) |