equinor / xtgeo

XTGeo Python class library for subsurface Surfaces, Cubes, Wells, Grids, Points, etc
https://xtgeo.readthedocs.io/en/latest/
GNU Lesser General Public License v3.0
109 stars 57 forks source link

Compiler warnings in C code #904

Open mferrera opened 1 year ago

mferrera commented 1 year ago

There are a few compiler warnings issued when building cxtgeo:

gcc

src/clib/xtg/grdcp3d_get_vtk_esg_geometry_data.c: In function ‘grdcp3d_get_vtk_esg_geometry_data’:
src/clib/xtg/grdcp3d_get_vtk_esg_geometry_data.c:117:16: warning: unused variable ‘finalConnCount’ [-Wunused-variable]
  117 |     const long finalConnCount = gm_connectivityCount(gm);
      |                ^~~~~~~~~~~~~~
src/clib/xtg/grd3d_points_ijk_cells.c: In function ‘grd3d_points_ijk_cells’:
src/clib/xtg/grd3d_points_ijk_cells.c:301:26: warning: ‘score’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  301 |             ibscore[nib] = score;
      |             ~~~~~~~~~~~~~^~~~~~~
src/clib/xtg/grd3d_points_ijk_cells.c:286:9: note: ‘score’ was declared here
  286 |     int score;
      |         ^~~~~
In file included from /usr/include/string.h:633,
                 from src/clib/xtg/except.c:6:
src/clib/xtg/except.c: In function ‘throw_exception’:
src/clib/xtg/except.c:14:5: warning: ‘__builtin_strncpy’ specified bound 256 equals destination size [-Wstringop-truncation]
   14 |     strncpy(error_message, msg, 256);
      |     ^~~~~~~

clang on macOS

src/clib/xtg/surf_get_z_from_xy.c:130:16: warning: variable 'z' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
      } else if (option == 2) {
                 ^~~~~~~~~~~
  src/clib/xtg/surf_get_z_from_xy.c:136:12: note: uninitialized use occurs here
      return z;
             ^
  src/clib/xtg/surf_get_z_from_xy.c:130:12: note: remove the 'if' if its condition is always true
      } else if (option == 2) {
             ^~~~~~~~~~~~~~~~~
KetilN commented 11 months ago

https://github.com/equinor/xtgeo/pull/1041 is now merged which should remove the warning in this file: src/clib/xtg/surf_get_z_from_xy.c

KetilN commented 11 months ago

PR "#1058 CLN: Remove unused variable in grdcp3d_get_vtk_esg_geometry_data.c " is now merged.

KetilN commented 11 months ago

PR "#1063 CLN: In C-code: Remove unused function, init variable and fix 'strncpy maxlen'" is now merged.

Still some macOS related tasks in this issue that might be postponed until macOS test environment is available.