Skip to content

UB fixes

Andrei Shamshur requested to merge rushmash/gnome-commander:ub-fixes into master

fix several C++ ub cases detected by cppcheck and clang-tidy tool

cppcheck:

src/imageloader.cc:202:25: error: Array 'names[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]
            return names[3];

clang-tidy:

../src/gnome-cmd-convert.cc:154:25: warning: Use of memory after it is freed [clang-analyzer-unix.Malloc]
  154 |     gchar *i = string = g_strchomp (string);
      |                         ^           ~~~~~~
../src/gnome-cmd-convert.cc:119:9: note: Assuming 'string' is non-null
  119 |     if (!string || !*string)
      |         ^~~~~~~
../src/gnome-cmd-convert.cc:119:9: note: Left side of '||' is false
../src/gnome-cmd-convert.cc:119:20: note: Assuming the condition is false
  119 |     if (!string || !*string)
      |                    ^~~~~~~~
../src/gnome-cmd-convert.cc:119:5: note: Taking false branch
  119 |     if (!string || !*string)
      |     ^
../src/gnome-cmd-convert.cc:151:5: note: Calling 'gcmd_convert_lowercase'
  151 |     gcmd_convert_lowercase (string);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/gnome-cmd-convert.cc:91:10: note: 'string' is non-null
   91 |     if (!string || !*string)
      |          ^~~~~~
../src/gnome-cmd-convert.cc:91:9: note: Left side of '||' is false
   91 |     if (!string || !*string)
      |         ^
../src/gnome-cmd-convert.cc:91:5: note: Taking false branch
   91 |     if (!string || !*string)
      |     ^
../src/gnome-cmd-convert.cc:96:5: note: Memory is released
   96 |     g_free (string);
      |     ^~~~~~~~~~~~~~~
../src/gnome-cmd-convert.cc:151:5: note: Returning; memory was released via 1st parameter
  151 |     gcmd_convert_lowercase (string);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/gnome-cmd-convert.cc:154:25: note: Use of memory after it is freed
  154 |     gchar *i = string = g_strchomp (string);

Merge request reports