From fa4c85eba5f15ec490aa9253c6b072f202905ed0 Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Mon, 12 Jan 2015 01:19:25 +0000 Subject: [PATCH] Another bug found by valgrind. --- mode_s.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/mode_s.c b/mode_s.c index 737b480..d2ea0ed 100644 --- a/mode_s.c +++ b/mode_s.c @@ -1753,9 +1753,11 @@ void detectModeS(uint16_t *m, uint32_t mlen) { } // Ensure msglen is consistent with the DF type - i = modesMessageLenByType(msg[0] >> 3); - if (msglen > i) {msglen = i;} - else if (msglen < i) {msglen = 0;} + if (msglen > 0) { + i = modesMessageLenByType(msg[0] >> 3); + if (msglen > i) {msglen = i;} + else if (msglen < i) {msglen = 0;} + } // // If we guessed at any of the bits in the DF type field, then look to see if our guess was sensible. @@ -2256,9 +2258,11 @@ void detectModeS_oversample(uint16_t *m, uint32_t mlen) { } // Ensure msglen is consistent with the DF type - i = modesMessageLenByType(msg[0] >> 3); - if (msglen > i) {msglen = i;} - else if (msglen < i) {msglen = 0;} + if (msglen > 0) { + i = modesMessageLenByType(msg[0] >> 3); + if (msglen > i) {msglen = i;} + else if (msglen < i) {msglen = 0;} + } // // If we guessed at any of the bits in the DF type field, then look to see if our guess was sensible.