From d2737e60270d41216df809a40c37c4f2f2e11ebb Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Fri, 13 May 2022 13:07:21 +0200 Subject: [PATCH] coding: Refactor function to avoid gcc false positive warn """ /libosmocore/src/coding/gsm0503_coding.c: In function 'osmo_conv_decode_ber_punctured': /libosmocore/src/coding/gsm0503_coding.c:563:31: error: 'coded_len' may be used uninitialized [-Werror=maybe-uninitialized] 563 | *n_bits_total = coded_len; | ~~~~~~~~~~~~~~^~~~~~~~~~~ /libosmocore/src/coding/gsm0503_coding.c:541:21: note: 'coded_len' was declared here 541 | int res, i, coded_len; | ^~~~~~~~~ """ This error is really a false positive. However, it is true that the code used to be a bit more complex than required, since the 2 later conditions could be inside the first one. Let's simply do early termination to simplify the function, and get rid of the gcc warning. Change-Id: I31ebf0c4be61daf6395d9a9fac05c7fdceb8bcb9 --- src/coding/gsm0503_coding.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/coding/gsm0503_coding.c b/src/coding/gsm0503_coding.c index 835a18e20..493f957f8 100644 --- a/src/coding/gsm0503_coding.c +++ b/src/coding/gsm0503_coding.c @@ -543,10 +543,11 @@ static int osmo_conv_decode_ber_punctured(const struct osmo_conv_code *code, res = osmo_conv_decode(code, input, output); - if (n_bits_total || n_errors) { - coded_len = osmo_conv_encode(code, output, recoded); - OSMO_ASSERT(sizeof(recoded) / sizeof(recoded[0]) >= coded_len); - } + if (!n_bits_total && !n_errors) + return res; + + coded_len = osmo_conv_encode(code, output, recoded); + OSMO_ASSERT(sizeof(recoded) / sizeof(recoded[0]) >= coded_len); /* Count bit errors */ if (n_errors) {