stcorp / coda

The Common Data Access toolset
http://stcorp.github.io/coda/doc/html/index.html
BSD 3-Clause "New" or "Revised" License
37 stars 17 forks source link

Compiler warnings when compiling coda #100

Closed svniemeijer closed 8 months ago

svniemeijer commented 9 months ago

The following warnings look like potential memory corruption issues and should be fixed:

libcoda/coda-netcdf.c: In function 'read_att_array':
libcoda/coda-netcdf.c:472:21: warning: 'coda_netcdf_array_new' accessing 64 bytes in a region of size 8 [8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wstringop-overflow=-Wstringop-overflow=8;;]
  472 |             array = coda_netcdf_array_new(1, &size, basic_type);
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libcoda/coda-netcdf.c:472:21: note: referencing argument 2 of type 'long int[8]'
In file included from libcoda/coda-netcdf.c:32:
libcoda/coda-netcdf-internal.h:82:20: note: in a call to function 'coda_netcdf_array_new'
   82 | coda_netcdf_array *coda_netcdf_array_new(int num_dims, long dim[CODA_MAX_NUM_DIMS], coda_netcdf_basic_type *base_type);
      |                    ^~~~~~~~~~~~~~~~~~~~~
libcoda/coda-netcdf.c:472:21: warning: 'coda_netcdf_array_new' accessing 64 bytes in a region of size 8 [8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wstringop-overflow=-Wstringop-overflow=8;;]
  472 |             array = coda_netcdf_array_new(1, &size, basic_type);
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libcoda/coda-netcdf.c:472:21: note: referencing argument 2 of type 'long int[8]'
libcoda/coda-netcdf-internal.h:82:20: note: in a call to function 'coda_netcdf_array_new'
   82 | coda_netcdf_array *coda_netcdf_array_new(int num_dims, long dim[CODA_MAX_NUM_DIMS], coda_netcdf_basic_type *base_type);
      |                    ^~~~~~~~~~~~~~~~~~~~~
libcoda/coda-netcdf.c:472:21: warning: 'coda_netcdf_array_new' accessing 64 bytes in a region of size 8 [8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wstringop-overflow=-Wstringop-overflow=8;;]
  472 |             array = coda_netcdf_array_new(1, &size, basic_type);
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libcoda/coda-netcdf.c:472:21: note: referencing argument 2 of type 'long int[8]'
libcoda/coda-netcdf-internal.h:82:20: note: in a call to function 'coda_netcdf_array_new'
   82 | coda_netcdf_array *coda_netcdf_array_new(int num_dims, long dim[CODA_MAX_NUM_DIMS], coda_netcdf_basic_type *base_type);
      |                    ^~~~~~~~~~~~~~~~~~~~~
libcoda/coda-hdf4-cursor.c: In function 'read_partial_array':
libcoda/coda-hdf4-cursor.c:813:26: warning: 'start' may be used uninitialized [8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wmaybe-uninitialized-Wmaybe-uninitialized8;;]
  813 |                 if (start[i] + edge[i] > type->dimsizes[i])
      |                     ~~~~~^~~
libcoda/coda-hdf4-cursor.c:706:11: note: 'start' declared here
  706 |     int32 start[MAX_HDF4_VAR_DIMS];
      |           ^~~~~
libcoda/coda-hdf4-cursor.c:813:36: warning: 'edge' may be used uninitialized [8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wmaybe-uninitialized-Wmaybe-uninitialized8;;]
  813 |                 if (start[i] + edge[i] > type->dimsizes[i])
      |                                ~~~~^~~
libcoda/coda-hdf4-cursor.c:708:11: note: 'edge' declared here
  708 |     int32 edge[MAX_HDF4_VAR_DIMS];
      |           ^~~~
svniemeijer commented 8 months ago

Fixed in 23a6f0e940c2ec2216eefd30f33e67d01e464601 and a57b367f40c15c1ce990073cac5bbf3d22e0219f.

Neither issue should be anything that would impact 'normal' usage of coda.