Project

General

Profile

Bug #3684

Always true/false conditions (reported by clang-4.0 with -Wall)

Added by fixeria 11 months ago. Updated 5 months ago.

Status:
Resolved
Priority:
Low
Assignee:
Category:
-
Target version:
-
Start date:
11/09/2018
Due date:
% Done:

100%

Resolution:

Description

Sorry for so brief and lazy report, no time.

db.c:278:25: warning: comparison of constant 256 with expression of type 'uint8_t' (aka 'unsigned char') is always false
      [-Wtautological-constant-out-of-range-compare]
        if (sms->user_data_len > sizeof(sms->user_data))
            ~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~
db.c:424:25: warning: comparison of constant 256 with expression of type 'uint8_t' (aka 'unsigned char') is always false
      [-Wtautological-constant-out-of-range-compare]
        if (sms->user_data_len > sizeof(sms->user_data))
            ~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~
db.c:780:25: warning: comparison of constant 256 with expression of type 'uint8_t' (aka 'unsigned char') is always false
      [-Wtautological-constant-out-of-range-compare]
        if (sms->user_data_len > sizeof(sms->user_data))
            ~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~
5 warnings generated.
osmo_msc.c:243:23: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
        if (conn->use_tokens < 0)
            ~~~~~~~~~~~~~~~~ ^ ~
osmo_msc.c:277:29: warning: comparison of constant 32 with expression of type 'enum msc_subscr_conn_use' is always true
      [-Wtautological-constant-out-of-range-compare]
                OSMO_ASSERT(balance_token < 32);
                            ~~~~~~~~~~~~~ ^ ~~
/usr/local/include/osmocom/core/utils.h:89:8: note: expanded from macro 'OSMO_ASSERT'
        if (!(exp)) { \
              ^~~
osmo_msc.c:304:29: warning: comparison of constant 32 with expression of type 'enum msc_subscr_conn_use' is always true
      [-Wtautological-constant-out-of-range-compare]
                OSMO_ASSERT(balance_token < 32);
                            ~~~~~~~~~~~~~ ^ ~~
/usr/local/include/osmocom/core/utils.h:89:8: note: expanded from macro 'OSMO_ASSERT'
        if (!(exp)) { \
              ^~~
smpp_openbsc.c:211:5: warning: comparison of constant 256 with expression of type 'uint8_t' (aka 'unsigned char') is always false
      [-Wtautological-constant-out-of-range-compare]
                                OSMO_MIN(ud_len, sizeof(sms->user_data)));
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/osmocom/core/utils.h:21:29: note: expanded from macro 'OSMO_MIN'
#define OSMO_MIN(a, b) ((a) >= (b) ? (b) : (a))
                        ~~~ ^  ~~~

History

#1 Updated by fixeria 11 months ago

How to reproduce all warnings:

$ ./configure --enable-smpp --enable-sanitize CC=clang-4.0
$ make

#2 Updated by fixeria 11 months ago

  • Priority changed from Normal to Low

#3 Updated by fixeria 7 months ago

  • Status changed from New to In Progress

Regarding the first three warnings:

db.c:278:25: warning: comparison of constant 256 with expression of type 'uint8_t' (aka 'unsigned char') is always false
      [-Wtautological-constant-out-of-range-compare]
        if (sms->user_data_len > sizeof(sms->user_data))
            ~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~
db.c:424:25: warning: comparison of constant 256 with expression of type 'uint8_t' (aka 'unsigned char') is always false
      [-Wtautological-constant-out-of-range-compare]
        if (sms->user_data_len > sizeof(sms->user_data))
            ~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~
db.c:780:25: warning: comparison of constant 256 with expression of type 'uint8_t' (aka 'unsigned char') is always false
      [-Wtautological-constant-out-of-range-compare]
        if (sms->user_data_len > sizeof(sms->user_data))
            ~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~

please see: https://gerrit.osmocom.org/#/c/osmo-msc/+/13470/

While investigating this and reading libdbi's documentation, I've also noticed the following (see 3.5.3):

dbi_result_get_field_length() returns the length in bytes of the value stored in the specified field. This is always one less than the size, and is probably only useful for fields containing strings.

Do we expect this? There is an alternative function:

dbi_result_get_field_size() returns the size in bytes of the value stored in the specified field. This is especially useful for string and binary data fields, which may have a dynamic size.

#4 Updated by fixeria 7 months ago

  • Status changed from In Progress to Feedback
  • Assignee set to fixeria
  • % Done changed from 0 to 90

Other warnings are most likely going to be resolved by the upcoming changes from neels/ho.

The last one:

smpp_openbsc.c:211:5: warning: comparison of constant 256 with expression of type 'uint8_t' (aka 'unsigned char') is always false
      [-Wtautological-constant-out-of-range-compare]
                                OSMO_MIN(ud_len, sizeof(sms->user_data)));
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/osmocom/core/utils.h:21:29: note: expanded from macro 'OSMO_MIN'
#define OSMO_MIN(a, b) ((a) >= (b) ? (b) : (a))
                        ~~~ ^  ~~~

can be safely ignored, I couldn't find any potential threats.

#5 Updated by fixeria 5 months ago

  • Status changed from Feedback to Resolved
  • % Done changed from 90 to 100

Most of warnings have been resolved. The only one left is related to the internal SMS Centre, which is going to be ripped out some day.

Also available in: Atom PDF

Add picture from clipboard (Maximum size: 48.8 MB)