rageworx / fltk-custom

A clone of FLTK 1.4.0 for enhance as customized GUI, more functional. This project is belong to https://fltk.org.
https://rageworx.info
Other
8 stars 1 forks source link

Prevent to overflow warning of Fl_Tabs. #39

Closed rageworx closed 1 year ago

rageworx commented 1 year ago
Fl_Tabs.cxx: In member function 'void Fl_Tabs::handle_overflow_menu()':
Fl_Tabs.cxx:256:9: warning: 'void* memset(void*, int, size_t)' specified bound b
etween 18446743953450467384 and 18446744073709551560 exceeds maximum object size
 9223372036854775807 [-Wstringop-overflow=]
  256 |   memset(overflow_menu, 0, sizeof(Fl_Menu_Item)*(nc+1));
      |   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fl_Tabs.cxx:256:9: warning: 'void* memset(void*, int, size_t)' specified bound b
etween 18446743953450467384 and 18446744073709551560 exceeds maximum object size
 9223372036854775807 [-Wstringop-overflow=]
rageworx commented 1 year ago

Code is

// create a menu with all children
  overflow_menu = new Fl_Menu_Item[nc+1];
  memset(overflow_menu, 0, sizeof(Fl_Menu_Item)*(nc+1));
  for (i = 0; i < nc; i++) {
    overflow_menu[i].label(child(i)->label());
    overflow_menu[i].user_data(child(i));
    overflow_menu[i].labelfont(labelfont());
    overflow_menu[i].labelsize(labelsize());
    if ( (i == fv) || (i == lv) )
      overflow_menu[i].flags |= FL_MENU_DIVIDER;
    if (child(i)->visible())
      overflow_menu[i].labelfont_ |= FL_BOLD;
  }
rageworx commented 1 year ago

It looks g++ sense to memset() size as pointer, maybe cast to size_t may should fix this warning.

rageworx commented 1 year ago

It should avoid size overflow warning by

  overflow_menu = new Fl_Menu_Item[nc+1];
  size_t overflow_menu_clrsz = sizeof(Fl_Menu_Item) * ((size_t)nc+1);
  memset(overflow_menu, 0, overflow_menu_clrsz);
rageworx commented 1 year ago

Or

  // create a menu with all children
  overflow_menu = new Fl_Menu_Item[nc+1];
  memset(overflow_menu, 0, sizeof(Fl_Menu_Item) * ((size_t)nc+1));
rageworx commented 1 year ago

Issue solved at commit of 314029d..1d5ebd8.

rageworx commented 1 year ago

Code updated to using latest type :

  overflow_menu = new Fl_Menu_Item[nc+1];
  memset(overflow_menu, 0, sizeof(Fl_Menu_Item) * ((size_t)nc+1));

commit = 1d5ebd8..1657357