Thread

Commits

  1. Fix printf format to use %zd when printing sizes

  1. mvstats triggers 32bit warnings

    Andres Freund <andres@anarazel.de> — 2017-04-07T21:40:22Z

    Hi,
    
    compiling on linux 32 bit I get a lot of warnings due to printf format.
    I suspect most of them should just be cured by using %zd or %zu instead
    of %ld.
    
    /home/andres/src/postgresql/src/backend/statistics/mvdistinct.c: In function ‘statext_ndistinct_deserialize’:
    /home/andres/src/postgresql/src/backend/statistics/mvdistinct.c:241:15: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 3 has type ‘unsigned int’ [-Wformat=]
       elog(ERROR, "invalid MVNDistinct size %ld (expected at least %ld)",
                   ^
    /home/andres/src/postgresql/src/include/utils/elog.h:202:23: note: in definition of macro ‘elog’
       elog_finish(elevel, __VA_ARGS__); \
                           ^~~~~~~~~~~
    /home/andres/src/postgresql/src/backend/statistics/mvdistinct.c:241:15: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 4 has type ‘unsigned int’ [-Wformat=]
       elog(ERROR, "invalid MVNDistinct size %ld (expected at least %ld)",
                   ^
    /home/andres/src/postgresql/src/include/utils/elog.h:202:23: note: in definition of macro ‘elog’
       elog_finish(elevel, __VA_ARGS__); \
                           ^~~~~~~~~~~
    /home/andres/src/postgresql/src/backend/statistics/mvdistinct.c:277:13: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘unsigned int’ [-Wformat=]
          errmsg("invalid MVNDistinct size %ld (expected at least %ld)",
                 ^
    /home/andres/src/postgresql/src/include/utils/elog.h:107:14: note: in definition of macro ‘ereport_domain’
        errfinish rest; \
                  ^~~~
    /home/andres/src/postgresql/src/backend/statistics/mvdistinct.c:275:3: note: in expansion of macro ‘ereport’
       ereport(ERROR,
       ^~~~~~~
    /home/andres/src/postgresql/src/backend/statistics/mvdistinct.c:277:13: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 3 has type ‘Size {aka unsigned int}’ [-Wformat=]
          errmsg("invalid MVNDistinct size %ld (expected at least %ld)",
                 ^
    /home/andres/src/postgresql/src/include/utils/elog.h:107:14: note: in definition of macro ‘ereport_domain’
        errfinish rest; \
                  ^~~~
    /home/andres/src/postgresql/src/backend/statistics/mvdistinct.c:275:3: note: in expansion of macro ‘ereport’
       ereport(ERROR,
       ^~~~~~~
    In file included from /home/andres/src/postgresql/src/include/postgres.h:48:0,
                     from /home/andres/src/postgresql/src/backend/statistics/dependencies.c:14:
    /home/andres/src/postgresql/src/backend/statistics/dependencies.c: In function ‘statext_dependencies_deserialize’:
    /home/andres/src/postgresql/src/backend/statistics/dependencies.c:514:15: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 3 has type ‘unsigned int’ [-Wformat=]
       elog(ERROR, "invalid MVDependencies size %ld (expected at least %ld)",
                   ^
    /home/andres/src/postgresql/src/include/utils/elog.h:202:23: note: in definition of macro ‘elog’
       elog_finish(elevel, __VA_ARGS__); \
                           ^~~~~~~~~~~
    /home/andres/src/postgresql/src/backend/statistics/dependencies.c:514:15: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 4 has type ‘unsigned int’ [-Wformat=]
       elog(ERROR, "invalid MVDependencies size %ld (expected at least %ld)",
                   ^
    /home/andres/src/postgresql/src/include/utils/elog.h:202:23: note: in definition of macro ‘elog’
       elog_finish(elevel, __VA_ARGS__); \
                           ^~~~~~~~~~~
    /home/andres/src/postgresql/src/backend/statistics/dependencies.c:550:15: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 3 has type ‘unsigned int’ [-Wformat=]
       elog(ERROR, "invalid dependencies size %ld (expected at least %ld)",
                   ^
    /home/andres/src/postgresql/src/include/utils/elog.h:202:23: note: in definition of macro ‘elog’
       elog_finish(elevel, __VA_ARGS__); \
                           ^~~~~~~~~~~
    /home/andres/src/postgresql/src/backend/statistics/dependencies.c:550:15: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 4 has type ‘Size {aka unsigned int}’ [-Wformat=]
       elog(ERROR, "invalid dependencies size %ld (expected at least %ld)",
                   ^
    - Andres
    
    
    
  2. Re: mvstats triggers 32bit warnings

    Alvaro Herrera <alvherre@2ndquadrant.com> — 2017-04-07T22:30:57Z

    Andres Freund wrote:
    > Hi,
    > 
    > compiling on linux 32 bit I get a lot of warnings due to printf format.
    > I suspect most of them should just be cured by using %zd or %zu instead
    > of %ld.
    
    You're right, they are.  Confirmed, and pushed fix using %zd.  I suppose
    %zu would be "more correct", but this doesn't raise warnings anymore.
    
    -- 
    Álvaro Herrera                https://www.2ndQuadrant.com/
    PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services