Warnings: Integer conversion resulted in a change of sign

Description

Many modules and the Font conversion tool have code that assign signed values to unsigned variables. This results is thousands of warnings for: “integer conversion resulted in a change of sign”

What MCU/Processor/Board and compiler are you using?

Processor is STM32F4
IDE is KEIL uVision MDK 5.27.1 with ARM V5.06 Update 6 toolchain.

What do you experience?

By default the ARM toolchain presents a warning if a signed value is assigned to an unsigned variable. When compiling code I recieve multiple warnings.

For example, compiling lv_draw_img.c

compiling lv_draw_img.c...
..\..\lvgl\src\lv_draw\lv_draw_img.c(53): warning:  #68-D: integer conversion resulted in a change of sign
          lv_draw_label(coords, mask, &lv_style_plain, LV_OPA_COVER, "No\ndata", LV_TXT_FLAG_NONE, NULL, -1, -1, NULL);
..\..\lvgl\src\lv_draw\lv_draw_img.c(53): warning:  #68-D: integer conversion resulted in a change of sign
          lv_draw_label(coords, mask, &lv_style_plain, LV_OPA_COVER, "No\ndata", LV_TXT_FLAG_NONE, NULL, -1, -1, NULL);
..\..\lvgl\src\lv_draw\lv_draw_img.c(63): warning:  #68-D: integer conversion resulted in a change of sign
          lv_draw_label(coords, mask, &lv_style_plain, LV_OPA_COVER, "No\ndata", LV_TXT_FLAG_NONE, NULL, -1, -1, NULL);
..\..\lvgl\src\lv_draw\lv_draw_img.c(63): warning:  #68-D: integer conversion resulted in a change of sign
          lv_draw_label(coords, mask, &lv_style_plain, LV_OPA_COVER, "No\ndata", LV_TXT_FLAG_NONE, NULL, -1, -1, NULL);
..\..\lvgl\src\lv_draw\lv_draw_img.c(496): warning:  #68-D: integer conversion resulted in a change of sign
          lv_draw_label(coords, mask, &lv_style_plain, LV_OPA_COVER, cdsc->dec_dsc.error_msg, LV_TXT_FLAG_NONE, NULL, -1, -1, NULL);
..\..\lvgl\src\lv_draw\lv_draw_img.c(497): warning:  #68-D: integer conversion resulted in a change of sign

What do you expect?

Assigning variables and parameters should either, use appropriate sign, or the value should be cast, or use a pre-compile define to prevent warnings.

Code to reproduce

Example code that produces the warning from lv_draw_img.c line 53. The -1 in the parameter generates the warning.

lv_draw_label(coords, mask, &lv_style_plain, LV_OPA_COVER, "No\ndata", LV_TXT_FLAG_NONE, NULL, -1, -1, NULL);

Example code that produces the warning from lv_font_roboto_12.c line 1032. The -2 assignment to .ofs_y generates a warning.

{.bitmap_index = 49, .adv_w = 112, .box_h = 12, .box_w = 7, .ofs_x = 0, .ofs_y = -2},

CORRECTION:
The kern_class_values are what are generating warnings.

static const uint8_t kern_class_values[] =
{
    0, -16, 22, 0, 0, -59, -16, -45,
...

I believe the second one has already been fixed in dev-6.1.

I’m not sure about the first one.

As @embeddedt mentioned the font related issue is fixed and will be released in v6.1.

I’v just fixed the issue of lv_draw_label in dev-6.1.

Thanks, Verified that the parameter warnings are fixed in dev 6.1

Investigating the fonts I found that the kern_class_values should be ints instead of uints and that fixes the warnings I was receiving with fonts.

uint8_t kern_class_values

changed to

int8_t kern_class_values

as they get assigned to the class_pair_values which are already defined as int8_t.

const int8_t * class_pair_values;    /*left_class_num * right_class_num value*/

I See that Github issue #1213 was already opened for the kern_class_values and fixed. Sorry for not checking there first.

I consider all the issues raised in this thread resolved.

1 Like