[GRASS-dev] suspicious warnings while compiling GRASS trunk (r38973)

  When building GRASS trunk (as of r38973) on an amd64 system,
  I've spotted the following warnings that look a bit suspicious.

  I have no time now to investigate these further, but perhaps
  someone could take a look?

make[3]: Entering directory `/.../grass-trunk-r38973/lib/gis'
spawn.c:474: warning: cast from pointer to integer of different size
spawn.c:478: warning: cast from pointer to integer of different size
spawn.c:479: warning: cast from pointer to integer of different size
spawn.c:482: warning: cast from pointer to integer of different size
spawn.c:487: warning: cast from pointer to integer of different size
spawn.c:488: warning: cast from pointer to integer of different size
spawn.c:489: warning: cast from pointer to integer of different size
spawn.c:494: warning: cast from pointer to integer of different size
spawn.c:495: warning: cast from pointer to integer of different size
spawn.c:501: warning: cast from pointer to integer of different size
spawn.c:502: warning: cast from pointer to integer of different size
spawn.c:503: warning: cast from pointer to integer of different size
spawn.c:504: warning: cast from pointer to integer of different size
spawn.c:509: warning: cast from pointer to integer of different size
spawn.c:515: warning: cast from pointer to integer of different size
spawn.c:521: warning: cast from pointer to integer of different size
spawn.c:524: warning: cast from pointer to integer of different size
spawn.c:528: warning: cast from pointer to integer of different size
spawn.c:548: warning: cast from pointer to integer of different size
spawn.c:552: warning: cast from pointer to integer of different size
spawn.c:561: warning: cast from pointer to integer of different size
spawn.c:568: warning: cast from pointer to integer of different size
spawn.c:575: warning: cast from pointer to integer of different size
spawn.c:583: warning: cast from pointer to integer of different size
spawn.c:589: warning: cast from pointer to integer of different size
spawn.c:595: warning: cast from pointer to integer of different size
spawn.c:598: warning: cast from pointer to integer of different size
spawn.c:602: warning: cast from pointer to integer of different size

trim_dec.c:30: warning: 'return' with a value, in function returning void

make[3]: Entering directory `/.../grass-trunk-r38973/lib/gmath'
/.../grass-trunk-r38973/dist.x86_64-unknown-linux-gnu/include/grass/gmath.h:72: warning: parameter names (without types) in function declaration
/.../grass-trunk-r38973/dist.x86_64-unknown-linux-gnu/include/grass/gmath.h:74: warning: parameter names (without types) in function declaration
/.../grass-trunk-r38973/dist.x86_64-unknown-linux-gnu/include/grass/gmath.h:86: warning: parameter names (without types) in function declaration

make[3]: Entering directory `/.../grass-trunk-r38973/lib/cluster'
c_assign.c:34: warning: passing argument 1 of 'G_debug' makes integer from pointer without a cast
c_assign.c:34: warning: passing argument 2 of 'G_debug' makes pointer from integer without a cast

make[3]: Entering directory `/.../grass-trunk-r38973/lib/sites'
sites.c:621: warning: cast from pointer to integer of different size
sites.c:643: warning: cast from pointer to integer of different size
sites.c:660: warning: cast from pointer to integer of different size
sites.c:714: warning: cast from pointer to integer of different size
sites.c:714: warning: cast from pointer to integer of different size
sites.c:788: warning: cast from pointer to integer of different size
sites.c:790: warning: cast from pointer to integer of different size
sites.c:790: warning: cast from pointer to integer of different size
sites.c:796: warning: cast from pointer to integer of different size
sites.c:798: warning: cast from pointer to integer of different size
sites.c:798: warning: cast from pointer to integer of different size
sites.c:808: warning: cast from pointer to integer of different size
sites.c:810: warning: cast from pointer to integer of different size
sites.c:810: warning: cast from pointer to integer of different size
sites.c:814: warning: cast from pointer to integer of different size
sites.c:823: warning: cast from pointer to integer of different size
sites.c:836: warning: cast from pointer to integer of different size
sites.c:838: warning: cast from pointer to integer of different size
sites.c:838: warning: cast from pointer to integer of different size
sites.c:848: warning: cast from pointer to integer of different size
sites.c:850: warning: cast from pointer to integer of different size
sites.c:850: warning: cast from pointer to integer of different size
sites.c:858: warning: cast from pointer to integer of different size
sites.c:858: warning: cast from pointer to integer of different size
sites.c:872: warning: cast from pointer to integer of different size
sites.c:874: warning: cast from pointer to integer of different size
sites.c:874: warning: cast from pointer to integer of different size
sites.c:933: warning: cast from pointer to integer of different size
sites.c:947: warning: cast from pointer to integer of different size
sites.c:948: warning: cast from pointer to integer of different size
sites.c:961: warning: cast from pointer to integer of different size
sites.c:963: warning: cast from pointer to integer of different size
sites.c:963: warning: cast from pointer to integer of different size
sites.c:966: warning: cast from pointer to integer of different size

make[2]: Entering directory `/.../grass-trunk-r38973/display/d.legend'
main.c:377: warning: passing argument 1 of 'Rast_get_c_cat' makes pointer from integer without a cast
main.c:408: warning: passing argument 1 of 'Rast_get_c_cat' from incompatible pointer type
main.c:607: warning: passing argument 1 of 'Rast_get_c_cat' makes pointer from integer without a cast
main.c:783: warning: passing argument 1 of 'Rast_get_c_cat' from incompatible pointer type
main.c:785: warning: passing argument 1 of 'Rast_get_c_cat' from incompatible pointer type

make[2]: Entering directory `/.../grass-trunk-r38973/raster/r.circle'
main.c:44: warning: cast from pointer to integer of different size

make[2]: Entering directory `/.../grass-trunk-r38973/raster/r.in.poly'
local_proto.h:3: warning: 'struct Categories' declared inside parameter list
local_proto.h:3: warning: its scope is only this definition or declaration, which is probably not what you want

make[3]: Entering directory `/.../grass-trunk-r38973/raster/r.li/r.li.shape'
map.c:344: warning: cast to pointer from integer of different size

make[3]: Entering directory `/.../grass-trunk-r38973/raster/r.li/r.li.padsd'
xround.c:24: warning: conflicting types for built-in function 'round'

make[2]: Entering directory `/.../grass-trunk-r38973/raster/r.out.vtk'
pv.h:33: warning: 'struct Colors' declared inside parameter list
pv.h:33: warning: its scope is only this definition or declaration, which is probably not what you want
pv.h:33: warning: 'struct Colors' declared inside parameter list
pv.h:33: warning: its scope is only this definition or declaration, which is probably not what you want

make[2]: Entering directory `/.../grass-trunk-r38973/raster/r.statistics2'
method.h:33: warning: 'struct Categories' declared inside parameter list
method.h:33: warning: its scope is only this definition or declaration, which is probably not what you want
method.h:36: warning: 'struct Categories' declared inside parameter list
method.h:42: warning: 'struct Categories' declared inside parameter list
method.h:45: warning: 'struct Categories' declared inside parameter list
method.h:48: warning: 'struct Categories' declared inside parameter list
method.h:51: warning: 'struct Categories' declared inside parameter list
method.h:54: warning: 'struct Categories' declared inside parameter list
method.h:57: warning: 'struct Categories' declared inside parameter list
method.h:60: warning: 'struct Categories' declared inside parameter list
method.h:63: warning: 'struct Categories' declared inside parameter list
method.h:66: warning: 'struct Categories' declared inside parameter list
method.h:69: warning: 'struct Categories' declared inside parameter list

make[2]: Entering directory `/.../grass-trunk-r38973/raster/r.to.vect'
areas_io.c:360: warning: passing argument 1 of 'Rast_get_c_cat' from incompatible pointer type

make[2]: Entering directory `/.../grass-trunk-r38973/vector/v.normal'
main.c:124: warning: cast from pointer to integer of different size

make[3]: Entering directory `/.../grass-trunk-r38973/ps/ps.map'
ps_fclrtbl.c:217: warning: cast from pointer to integer of different size
ps_fclrtbl.c:217: warning: cast from pointer to integer of different size

make[1]: Entering directory `/.../grass-trunk-r38973/gem'
tools.c:56: warning: comparison with string literal results in unspecified behavior

--
FSF associate member #7257

Ivan Shmakov wrote:

  When building GRASS trunk (as of r38973) on an amd64 system,
  I've spotted the following warnings that look a bit suspicious.

  I have no time now to investigate these further, but perhaps
  someone could take a look?

make[3]: Entering directory `/.../grass-trunk-r38973/lib/gis'
spawn.c:474: warning: cast from pointer to integer of different size

These are safe. The values are small integers which have been cast to
pointers, so casting them back to integers is safe.

I don't think that the warnings can be eliminated.

trim_dec.c:30: warning: 'return' with a value, in function returning void

Fixed in r39000.

make[3]: Entering directory `/.../grass-trunk-r38973/lib/gmath'
/.../grass-trunk-r38973/dist.x86_64-unknown-linux-gnu/include/grass/gmath.h:72: warning: parameter names (without types) in function declaration
/.../grass-trunk-r38973/dist.x86_64-unknown-linux-gnu/include/grass/gmath.h:74: warning: parameter names (without types) in function declaration
/.../grass-trunk-r38973/dist.x86_64-unknown-linux-gnu/include/grass/gmath.h:86: warning: parameter names (without types) in function declaration

Needs <stddef.h> for size_t; fixed in r39006.

make[3]: Entering directory `/.../grass-trunk-r38973/lib/cluster'
c_assign.c:34: warning: passing argument 1 of 'G_debug' makes integer from pointer without a cast
c_assign.c:34: warning: passing argument 2 of 'G_debug' makes pointer from integer without a cast

Debug level omitted; fixed in r39001.

make[3]: Entering directory `/.../grass-trunk-r38973/lib/sites'
sites.c:621: warning: cast from pointer to integer of different size

Used (char)NULL instead of '\0' for NUL byte; harmless other than the
warnings; fixed in r39002.

make[2]: Entering directory `/.../grass-trunk-r38973/display/d.legend'
main.c:377: warning: passing argument 1 of 'Rast_get_c_cat' makes pointer from integer without a cast
main.c:408: warning: passing argument 1 of 'Rast_get_c_cat' from incompatible pointer type
main.c:607: warning: passing argument 1 of 'Rast_get_c_cat' makes pointer from integer without a cast
main.c:783: warning: passing argument 1 of 'Rast_get_c_cat' from incompatible pointer type
main.c:785: warning: passing argument 1 of 'Rast_get_c_cat' from incompatible pointer type

These are actual errors; I'll look into this later.

make[2]: Entering directory `/.../grass-trunk-r38973/raster/r.circle'
main.c:44: warning: cast from pointer to integer of different size

Harmless, but both the initialisation and the FILEDESC typedef were
gratuituous; fixed in r39005.

make[2]: Entering directory `/.../grass-trunk-r38973/raster/r.in.poly'
local_proto.h:3: warning: 'struct Categories' declared inside parameter list
local_proto.h:3: warning: its scope is only this definition or declaration, which is probably not what you want

Needs <grass/raster.h>; fixed in r39007.

make[3]: Entering directory `/.../grass-trunk-r38973/raster/r.li/r.li.shape'
map.c:344: warning: cast to pointer from integer of different size

The named file doesn't exist in this directory.

make[3]: Entering directory `/.../grass-trunk-r38973/raster/r.li/r.li.padsd'
xround.c:24: warning: conflicting types for built-in function 'round'

Likewise.

make[2]: Entering directory `/.../grass-trunk-r38973/raster/r.out.vtk'
pv.h:33: warning: 'struct Colors' declared inside parameter list
pv.h:33: warning: its scope is only this definition or declaration, which is probably not what you want
pv.h:33: warning: 'struct Colors' declared inside parameter list
pv.h:33: warning: its scope is only this definition or declaration, which is probably not what you want

Likewise.

make[2]: Entering directory `/.../grass-trunk-r38973/raster/r.statistics2'
method.h:33: warning: 'struct Categories' declared inside parameter list
method.h:33: warning: its scope is only this definition or declaration, which is probably not what you want

Likewise.

make[2]: Entering directory `/.../grass-trunk-r38973/raster/r.to.vect'
areas_io.c:360: warning: passing argument 1 of 'Rast_get_c_cat' from incompatible pointer type

This is an actual error, similar to d.legend. I'll look into this later.

make[2]: Entering directory `/.../grass-trunk-r38973/vector/v.normal'
main.c:124: warning: cast from pointer to integer of different size

Another (char)NULL case; fixed in r39010.

make[3]: Entering directory `/.../grass-trunk-r38973/ps/ps.map'
ps_fclrtbl.c:217: warning: cast from pointer to integer of different size
ps_fclrtbl.c:217: warning: cast from pointer to integer of different size

This introduces an actual bug on 64-bit systems. Fixed in r39011.

make[1]: Entering directory `/.../grass-trunk-r38973/gem'
tools.c:56: warning: comparison with string literal results in unspecified behavior

Fixed in r39014.

--
Glynn Clements <glynn@gclements.plus.com>

n Sat, Sep 5, 2009 at 8:38 PM, Glynn Clements<glynn@gclements.plus.com> wrote:

Ivan Shmakov wrote:

  When building GRASS trunk \(as of r38973\) on an amd64 system,
  I&#39;ve spotted the following warnings that look a bit suspicious\.

[Glynn's comments/fixes]

I have backported all related fixes from Glynn to 6.5.svn and 6.4.svn.

Markus

Glynn Clements <glynn@gclements.plus.com> writes:

  Thanks for a timely response!

[...]

>> make[3]: Entering directory `/.../grass-trunk-r38973/raster/r.li/r.li.shape' map.c:344: warning:
>> cast to pointer from integer of different size

> The named file doesn't exist in this directory.

  Oops! I'll try to re-build a fresh SVN trunk without `-j N' a
  bit later.

[...]

--
FSF associate member #7257

make[2]: Entering directory `/var/home/ivan/devel/grass-trunk-r39080/raster/r.mapcalc'
map.c:344: warning: cast to pointer from integer of different size

  Not quite sure about this one.

xround.c:24: warning: conflicting types for built-in function 'round'

  Seems to be harmless, though may easily be silenced by, like:

--- raster/r.mapcalc/xround.c 2009-09-08 19:14:19.000000000 +0700
+++ raster/r.mapcalc/xround.c 2009-09-08 21:37:03.537188857 +0700
@@ -8,7 +8,7 @@
#include "func_proto.h"

/**********************************************************************
-round(x)
+i_round(x)

   rounds x to nearest integer.

@@ -19,9 +19,9 @@
   numbers, and subtracting .5 from negatives.
**********************************************************************/

-/* round(x) rounds x to nearest CELL value, handles negative correctly */
+/* i_round(x) rounds x to nearest CELL value, handles negative correctly */

-static int round(double x)
+static int i_round(double x)
{
     int n;

@@ -77,7 +77,7 @@
     if (IS_NULL_F(&arg1[i]))
         SET_NULL_C(&res[i]);
     else
- res[i] = round(arg1[i]);
+ res[i] = i_round(arg1[i]);
       return 0;
   }
     case DCELL_TYPE:
@@ -88,7 +88,7 @@
     if (IS_NULL_D(&arg1[i]))
         SET_NULL_C(&res[i]);
     else
- res[i] = round(arg1[i]);
+ res[i] = i_round(arg1[i]);
       return 0;
   }
     default:

make[2]: Entering directory `/var/home/ivan/devel/grass-trunk-r39080/raster/r.out.vrml'
pv.h:33: warning: 'struct Colors' declared inside parameter list
pv.h:33: warning: its scope is only this definition or declaration, which is probably not what you want
pv.h:33: warning: 'struct Colors' declared inside parameter list
pv.h:33: warning: its scope is only this definition or declaration, which is probably not what you want

  Needs #include <grass/raster.h>.

--- raster/r.out.vrml/pv.h 2009-09-08 19:14:16.000000000 +0700
+++ raster/r.out.vrml/pv.h 2009-09-08 21:43:16.353402293 +0700
@@ -1,4 +1,5 @@
#include <grass/gis.h>
+#include <grass/raster.h>

/* VRML VERSION - only 1.0 currently supported
    #define VRML2

make[2]: Entering directory `/var/home/ivan/devel/grass-trunk-r39080/raster/r.statistics'
method.h:33: warning: 'struct Categories' declared inside parameter list
method.h:33: warning: its scope is only this definition or declaration, which is probably not what you want
method.h:36: warning: 'struct Categories' declared inside parameter list
method.h:42: warning: 'struct Categories' declared inside parameter list
method.h:45: warning: 'struct Categories' declared inside parameter list
method.h:48: warning: 'struct Categories' declared inside parameter list
method.h:51: warning: 'struct Categories' declared inside parameter list
method.h:54: warning: 'struct Categories' declared inside parameter list
method.h:57: warning: 'struct Categories' declared inside parameter list
method.h:60: warning: 'struct Categories' declared inside parameter list
method.h:63: warning: 'struct Categories' declared inside parameter list
method.h:66: warning: 'struct Categories' declared inside parameter list
method.h:69: warning: 'struct Categories' declared inside parameter list

  Likewise.

--- raster/r.statistics/method.h 2009-09-08 19:14:04.000000000 +0700
+++ raster/r.statistics/method.h 2009-09-08 21:43:54.983370151 +0700
@@ -1,3 +1,5 @@
+#include <grass/raster.h>
+
#define DISTRIB 0
#define AVERAGE 1
#define MODE 2

  Unless there are to be objections, I'm going to commit the
  changes above to the trunk.

--
FSF associate member #7257

Ivan Shmakov wrote:

make[2]: Entering directory `/var/home/ivan/devel/grass-trunk-r39080/raster/r.mapcalc'
map.c:344: warning: cast to pointer from integer of different size

  Not quite sure about this one.

This is a bug, introduced in r38099, along with simlar bugs affecting
d.legend and r.to.vect.

G_get_cat() took a CELL argument (so FCELL or DCELL arguments will be
implicitly cast).

Rast_get_c_cat() takes a CELL* and Rast_get_cat() takes a void*.
Passing the value itself is an error, as is passing a pointer to the
wrong numeric type.

It appears that calls to G_get_cat() were initially replaced with
Rast_get_cat(). This will produce errors due to the wrong number of
arguments (Rast_get_cat() also needs a RASTER_MAP_TYPE argument). So
it was changed to Rast_get_c_cat(), which has the right number of
arguments, but the wrong types, hence the errors.

I've fixed these specific cases with r39133, but I can't rule out the
possibility that others may have been hidden by casts.

xround.c:24: warning: conflicting types for built-in function 'round'

  Seems to be harmless, though may easily be silenced by, like:

Done in r39130, except:

/**********************************************************************
-round(x)
+i_round(x)

This is the name of the r.mapcalc function which the file implements,
so shouldn't be changed.

make[2]: Entering directory `/var/home/ivan/devel/grass-trunk-r39080/raster/r.out.vrml'
pv.h:33: warning: 'struct Colors' declared inside parameter list

  Needs #include <grass/raster.h>.

Fixed in r39131, plus some clean-up.

--- raster/r.statistics/method.h 2009-09-08 19:14:04.000000000 +0700
+++ raster/r.statistics/method.h 2009-09-08 21:43:54.983370151 +0700
@@ -1,3 +1,5 @@
+#include <grass/raster.h>

Fixed in r39132 (also <stdio.h> for FILE).

--
Glynn Clements <glynn@gclements.plus.com>

On Sat, Sep 12, 2009 at 5:46 AM, Glynn Clements
<glynn@gclements.plus.com> wrote:

Ivan Shmakov wrote:

I have backported the relevant changes but I am unsure
about

r39134, Attempt to determine message encoding on Windows [relevant for R]
r39136, Fix diglib warnings

?
Markus

Markus Neteler wrote:

I have backported the relevant changes but I am unsure
about

r39134, Attempt to determine message encoding on Windows [relevant for R]

I think that this should be back-ported. Otherwise, I can't see
--with-nls working on Windows, as --interface-description will
generate invalid XML.

r39136, Fix diglib warnings

These mostly fix warnings related to Markus Metz' LFS changes, so
shouldn't be applicable to 6.4.

--
Glynn Clements <glynn@gclements.plus.com>

On Sun, Sep 13, 2009 at 1:32 AM, Glynn Clements
<glynn@gclements.plus.com> wrote:

Markus Neteler wrote:

I have backported the relevant changes but I am unsure about
r39134, Attempt to determine message encoding on Windows [relevant for R]

I think that this should be back-ported. Otherwise, I can't see
--with-nls working on Windows, as --interface-description will
generate invalid XML.

Ok, done (6.4 and 6.5).

r39136, Fix diglib warnings

These mostly fix warnings related to Markus Metz' LFS changes, so
shouldn't be applicable to 6.4.

Alright.

Markus

Glynn Clements wrote:

Markus Neteler wrote:
  [...]

r39136, Fix diglib warnings
    
These mostly fix warnings related to Markus Metz' LFS changes, so
shouldn't be applicable to 6.4.
  

Thanks, I couldn't come up with something that works on both 32 bit and 64 bit. Interesting solution you chose with PRI_OFF_T, I didn't know that is possible.

My compiler (gcc 4.3.2) on Linux 64bit now says that long long int is not the same like off_t, e.g.

cindex_rw.c:69: warning: format '%lld' expects type 'long long int', but argument 4 has type 'off_t'

although long long int and off_t are both of size 8 ???

Markus M

Markus Metz wrote:

>> r39136, Fix diglib warnings
>>
>
> These mostly fix warnings related to Markus Metz' LFS changes, so
> shouldn't be applicable to 6.4.

Thanks, I couldn't come up with something that works on both 32 bit and
64 bit. Interesting solution you chose with PRI_OFF_T, I didn't know
that is possible.

My compiler (gcc 4.3.2) on Linux 64bit now says that long long int is
not the same like off_t, e.g.

cindex_rw.c:69: warning: format '%lld' expects type 'long long int', but
argument 4 has type 'off_t'

although long long int and off_t are both of size 8 ???

Presumably your system defines off_t as "long". The compiler considers
"long" and "long long" to be different types, even if they are the
same size, in the same way that it considers "int" and "long" as
different types on 32-bit systems.

Did you use --enable-largefile? There shouldn't be any reason to do so
on a 64-bit system. Or does _FILE_OFFSET_BITS get defined to 64 even
without --enable-largefile?

Unfortunately, I don't think there's any straightforward way to detect
the underlying type for which off_t is an alias. Simply detecting the
size of a type is problematic (in 2.13, AC_CHECK_SIZEOF doesn't work
when cross-compiling).

--
Glynn Clements <glynn@gclements.plus.com>

Glynn Clements wrote:

Markus Metz wrote:

r39136, Fix diglib warnings
    

Thanks, I couldn't come up with something that works on both 32 bit and 64 bit. Interesting solution you chose with PRI_OFF_T, I didn't know that is possible.

My compiler (gcc 4.3.2) on Linux 64bit now says that long long int is not the same like off_t, e.g.

cindex_rw.c:69: warning: format '%lld' expects type 'long long int', but argument 4 has type 'off_t'

although long long int and off_t are both of size 8 ???
    
Did you use --enable-largefile?

No.

There shouldn't be any reason to do so
on a 64-bit system. Or does _FILE_OFFSET_BITS get defined to 64 even
without --enable-largefile?
  

Yes. I guess configure concludes that LFS is available which trickles down to _FILE_OFFSET_BITS defined to 64, even without --enable-largefile. BTW, this is not specific to the vector libs, raster modules with a corresponding Makefile also have _FILE_OFFSET_BITS defined to 64. I don't worry about that for my system but don't know if this can cause problems on other systems. The diglib warnings disappear if I use %ld instead of %lld, but that is system-specific, I don't know if this would work on Windows 64bit (assuming I found a 64bit compiling environment for Windows) or on Mac 64bit. Anyway, all these warnings are related to debug messages, and if need be, a developer trying to isolate a bug in the vector libs can easily change the printing format according to the current system.

The portability test however must be passed on any system as it is, and for that we need an integer type that is 64 bit long, and that is where the problems start if you don't want to rely on the C99 long long int. All that stuff with C99 and what compiler (version) supports which parts of C99 is beyond me, not to mention cross-compiling issues, so I would like to leave that to people who know something about it. I'm still astonished that vector libs LFS is working on my system...

Markus M