Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 2 #1

Merged
merged 1 commit into from
Apr 19, 2022
Merged

Fix issue 2 #1

merged 1 commit into from
Apr 19, 2022

Conversation

neurolabusc
Copy link

  • This fixes issue 2
  • For your pull request to the main branch, can you modify the code so it does not elicit warnings with Clang and gcc (I think you just need to explicity typecast the pointers):

Clang

meshify.c:713:37: warning: passing 'short [8]' to parameter of type 'unsigned short *' converts between pointers to integer types with different sign [-Wpointer-sign]
                if(jdata_decode((void **)&imgRaw, hdr->dim, hdr->dim+1, 3, &type, jniidata)!=0){
                                                  ^~~~~~~~
meshify.c:568:47: note: passing argument to parameter 'ndim' here
int  jdata_decode(void **vol, unsigned short *ndim, unsigned short *dims, int maxdim, char **type, cJSON *obj){
                                              ^
meshify.c:713:47: warning: passing 'short *' to parameter of type 'unsigned short *' converts between pointers to integer types with different sign [-Wpointer-sign]
                if(jdata_decode((void **)&imgRaw, hdr->dim, hdr->dim+1, 3, &type, jniidata)!=0){
                                                            ^~~~~~~~~~
meshify.c:568:69: note: passing argument to parameter 'dims' here
int  jdata_decode(void **vol, unsigned short *ndim, unsigned short *dims, int maxdim, char **type, cJSON *obj){
                                                                    ^
meshify.c:759:28: warning: passing 'short *' to parameter of type 'unsigned short *' converts between pointers to integer types with different sign [-Wpointer-sign]
                        array3d_row2col(&img32, hdr->dim+1);
                                                ^~~~~~~~~~
meshify.c:621:51: note: passing argument to parameter 'dim' here
void array3d_row2col(float **vol, unsigned short *dim){
                                                  ^
meshify.c:950:24: warning: passing 'unsigned int *' to parameter of type 'int *' converts between pointers to integer types with different sign [-Wpointer-sign]
                                        write_ubjsonint(1,&keylen,fp);
                                                          ^~~~~~~
meshify.c:856:36: note: passing argument to parameter 'dat' here
void write_ubjsonint(int len, int *dat, FILE *fp){
                                   ^
meshify.c:982:33: warning: passing 'unsigned int *' to parameter of type 'int *' converts between pointers to integer types with different sign [-Wpointer-sign]
                                                                write_ubjsonint(ntri*3, newtris, fp);
                                                                                        ^~~~~~~
meshify.c:856:36: note: passing argument to parameter 'dat' here
void write_ubjsonint(int len, int *dat, FILE *fp){

gcc

meshify.c: In function 'float* load_jnii(const char*, nifti_1_header*)':
meshify.c:713:56: error: invalid conversion from 'short int*' to 'short unsigned int*' [-fpermissive]
  713 |                 if(jdata_decode((void **)&imgRaw, hdr->dim, hdr->dim+1, 3, &type, jniidata)!=0){
      |                                                   ~~~~~^~~
      |                                                        |
      |                                                        short int*
meshify.c:568:47: note:   initializing argument 2 of 'int jdata_decode(void**, short unsigned int*, short unsigned int*, int, char**, cJSON*)'
  568 | int  jdata_decode(void **vol, unsigned short *ndim, unsigned short *dims, int maxdim, char **type, cJSON *obj){
      |                               ~~~~~~~~~~~~~~~~^~~~
meshify.c:713:69: error: invalid conversion from 'short int*' to 'short unsigned int*' [-fpermissive]
  713 |                 if(jdata_decode((void **)&imgRaw, hdr->dim, hdr->dim+1, 3, &type, jniidata)!=0){
      |                                                             ~~~~~~~~^~
      |                                                                     |
      |                                                                     short int*
meshify.c:568:69: note:   initializing argument 3 of 'int jdata_decode(void**, short unsigned int*, short unsigned int*, int, char**, cJSON*)'
  568 | int  jdata_decode(void **vol, unsigned short *ndim, unsigned short *dims, int maxdim, char **type, cJSON *obj){
      |                                                     ~~~~~~~~~~~~~~~~^~~~
meshify.c:759:57: error: invalid conversion from 'short int*' to 'short unsigned int*' [-fpermissive]
  759 |                         array3d_row2col(&img32, hdr->dim+1);
      |                                                 ~~~~~~~~^~
      |                                                         |
      |                                                         short int*
meshify.c:621:51: note:   initializing argument 2 of 'void array3d_row2col(float**, short unsigned int*)'
  621 | void array3d_row2col(float **vol, unsigned short *dim){
      |                                   ~~~~~~~~~~~~~~~~^~~
meshify.c: In function 'int save_bmsh(const char*, vec3i*, vec3d*, int, int, bool, bool)':
meshify.c:950:59: error: invalid conversion from 'unsigned int*' to 'int*' [-fpermissive]
  950 |                                         write_ubjsonint(1,&keylen,fp);
      |                                                           ^~~~~~~
      |                                                           |
      |                                                           unsigned int*
meshify.c:856:36: note:   initializing argument 2 of 'void write_ubjsonint(int, int*, FILE*)'
  856 | void write_ubjsonint(int len, int *dat, FILE *fp){
      |                               ~~~~~^~~
meshify.c:982:89: error: invalid conversion from 'unsigned int*' to 'int*' [-fpermissive]
  982 |                                                                 write_ubjsonint(ntri*3, newtris, fp);
      |                                                                                         ^~~~~~~
      |                                                                                         |
      |                                                                                         unsigned int
meshify.c:856:36: note:   initializing argument 2 of 'void write_ubjsonint(int, int*, FILE*)'
  856 | void write_ubjsonint(int len, int *dat, FILE *fp){

@fangq fangq merged commit 4e60564 into NeuroJSON:main Apr 19, 2022
fangq added a commit that referenced this pull request Apr 19, 2022
@fangq
Copy link
Member

fangq commented Apr 19, 2022

thanks. I ran gcc -Wall --pedantic, all warnings should be now fixed with the above commit. I just want you to take a look and see if any of the changes is unexpected - especially &littleEndianPlatform

$ gcc -Wall --pedantic -O3 -DNII2MESH -DHAVE_ZLIB -DHAVE_JSON cJSON.c MarchingCubes.c nii2mesh.c isolevel.c meshify.c quadric.c base64.c bwlabel.c radixsort.c -o nii2mesh -lz -lm

nii2mesh.c: In function ‘main’:
nii2mesh.c:363:0: warning: ignoring #pragma omp parallel [-Wunknown-pragmas]
   #pragma omp parallel private(partial_OK) shared(nOK)
 
nii2mesh.c:367:0: warning: ignoring #pragma omp for [-Wunknown-pragmas]
    #pragma omp for
 
nii2mesh.c:392:0: warning: ignoring #pragma omp critical [-Wunknown-pragmas]
    #pragma omp critical
 
meshify.c: In function ‘save_freesurfer’:
meshify.c:446:7: warning: the address of ‘littleEndianPlatform’ will always evaluate as ‘true’ [-Waddress]
  if ( &littleEndianPlatform) {
       ^
meshify.c:455:6: warning: the address of ‘littleEndianPlatform’ will always evaluate as ‘true’ [-Waddress]
  if (&littleEndianPlatform)
      ^
meshify.c:459:6: warning: the address of ‘littleEndianPlatform’ will always evaluate as ‘true’ [-Waddress]
  if (&littleEndianPlatform) {
      ^
meshify.c: In function ‘load_jnii’:
meshify.c:717:37: warning: pointer targets in passing argument 2 of ‘jdata_decode’ differ in signedness [-Wpointer-sign]
   if(jdata_decode((void **)&imgRaw, hdr->dim, hdr->dim+1, 3, &type, jniidata)!=0){
                                     ^~~
meshify.c:568:6: note: expected ‘short unsigned int *’ but argument is of type ‘short int *’
 int  jdata_decode(void **vol, unsigned short *ndim, unsigned short *dims, int maxdim, char **type, cJSON *obj){
      ^~~~~~~~~~~~
meshify.c:717:47: warning: pointer targets in passing argument 3 of ‘jdata_decode’ differ in signedness [-Wpointer-sign]
   if(jdata_decode((void **)&imgRaw, hdr->dim, hdr->dim+1, 3, &type, jniidata)!=0){
                                               ^~~
meshify.c:568:6: note: expected ‘short unsigned int *’ but argument is of type ‘short int *’
 int  jdata_decode(void **vol, unsigned short *ndim, unsigned short *dims, int maxdim, char **type, cJSON *obj){
      ^~~~~~~~~~~~
meshify.c:763:28: warning: pointer targets in passing argument 2 of ‘array3d_row2col’ differ in signedness [-Wpointer-sign]
    array3d_row2col(&img32, hdr->dim+1);
                            ^~~
meshify.c:621:6: note: expected ‘short unsigned int *’ but argument is of type ‘short int *’
 void array3d_row2col(float **vol, unsigned short *dim){
      ^~~~~~~~~~~~~~~
meshify.c: In function ‘write_ubjsonint’:
meshify.c:861:6: warning: the address of ‘littleEndianPlatform’ will always evaluate as ‘true’ [-Waddress]
  if (!&littleEndianPlatform)
      ^
meshify.c: In function ‘write_ubjsonfloat’:
meshify.c:867:6: warning: the address of ‘littleEndianPlatform’ will always evaluate as ‘true’ [-Waddress]
  if (!&littleEndianPlatform)
      ^
meshify.c: In function ‘write_ubjsondouble’:
meshify.c:873:6: warning: the address of ‘littleEndianPlatform’ will always evaluate as ‘true’ [-Waddress]
  if (!&littleEndianPlatform)
      ^
meshify.c: In function ‘save_bmsh’:
meshify.c:954:24: warning: pointer targets in passing argument 2 of ‘write_ubjsonint’ differ in signedness [-Wpointer-sign]
      write_ubjsonint(1,&keylen,fp);
                        ^
meshify.c:860:6: note: expected ‘int *’ but argument is of type ‘unsigned int *’
 void write_ubjsonint(int len, int *dat, FILE *fp){
      ^~~~~~~~~~~~~~~
meshify.c:986:33: warning: pointer targets in passing argument 2 of ‘write_ubjsonint’ differ in signedness [-Wpointer-sign]
         write_ubjsonint(ntri*3, newtris, fp);
                                 ^~~~~~~
meshify.c:860:6: note: expected ‘int *’ but argument is of type ‘unsigned int *’
 void write_ubjsonint(int len, int *dat, FILE *fp){
      ^~~~~~~~~~~~~~~
meshify.c:963:24: warning: variable ‘len’ set but not used [-Wunused-but-set-variable]
      int dim[2]={0,3}, len[2]={1,0};
                        ^~~
meshify.c: In function ‘save_mz3’:
meshify.c:1084:6: warning: the address of ‘littleEndianPlatform’ will always evaluate as ‘true’ [-Waddress]
  if (! &littleEndianPlatform)
      ^
meshify.c:1102:6: warning: the address of ‘littleEndianPlatform’ will always evaluate as ‘true’ [-Waddress]
  if (! &littleEndianPlatform) {
      ^
meshify.c:1126:6: warning: the address of ‘littleEndianPlatform’ will always evaluate as ‘true’ [-Waddress]
  if (! &littleEndianPlatform)
      ^
meshify.c: In function ‘save_ply’:
meshify.c:1224:6: warning: the address of ‘littleEndianPlatform’ will always evaluate as ‘true’ [-Waddress]
  if (&littleEndianPlatform)
      ^
meshify.c: In function ‘save_gii’:
meshify.c:1290:6: warning: the address of ‘littleEndianPlatform’ will always evaluate as ‘true’ [-Waddress]
  if (&littleEndianPlatform)
      ^
meshify.c:1332:6: warning: the address of ‘littleEndianPlatform’ will always evaluate as ‘true’ [-Waddress]
  if (&littleEndianPlatform)
      ^
meshify.c: In function ‘save_vtk’:
meshify.c:1391:6: warning: the address of ‘littleEndianPlatform’ will always evaluate as ‘true’ [-Waddress]
  if (&littleEndianPlatform)
      ^
meshify.c:1405:6: warning: the address of ‘littleEndianPlatform’ will always evaluate as ‘true’ [-Waddress]
  if (&littleEndianPlatform)
      ^
meshify.c: In function ‘save_mz3’:
meshify.c:1131:3: warning: ‘fgz’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   gzclose(fgz);
   ^~~~~~~~~~~~
meshify.c:1136:3: warning: ‘fp’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   fclose(fp);
   ^~~~~~~~~~
quadric.c: In function ‘quadric_simplify_mesh’:
quadric.c:452:7: warning: ‘iterationStartCount’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    if (iterationStartCount == (triangle_count-deleted_triangles)) break;
       ^

@neurolabusc
Copy link
Author

These all look fine. The compiler is right, littleEndianPlatform () always evaluates true for a little-endian architecture. It will always evaluate false on a big-endian system.

bool littleEndianPlatform () {
	uint32_t value = 1;
	return (*((char *) &value) == 1);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

segfault when meshing a volume with non-zero voxels on the bounding-box
2 participants