8000 Add missing format attributes · postgrespro/postgres_cluster@52ce205 · GitHub
[go: up one dir, main page]

Skip to content

Commit 52ce205

Browse files
committed
Add missing format attributes
Add __attribute__ decorations for printf format checking to the places that were missing them. Fix the resulting warnings. Add -Wmissing-format-attribute to the standard set of warnings for GCC, so these don't happen again. The warning fixes here are relatively harmless. The one serious problem discovered by this was already committed earlier in cf15fb5.
1 parent 96a8aed commit 52ce205

File tree

13 files changed

+87
-18
lines changed
  • contrib
  • src
  • 13 files changed

    +87
    -18
    lines changed

    configure

    Lines changed: 60 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -4123,6 +4123,66 @@ if test x"$pgac_cv_prog_cc_cflags__Wendif_labels" = x"yes"; then
    41234123
    CFLAGS="$CFLAGS -Wendif-labels"
    41244124
    fi
    41254125

    4126+
    { $as_echo "$as_me:$LINENO: checking whether $CC supports -Wmissing-format-attribute" >&5
    4127+
    $as_echo_n "checking whether $CC supports -Wmissing-format-attribute... " >&6; }
    4128+
    if test "${pgac_cv_prog_cc_cflags__Wmissing_format_attribute+set}" = set; then
    4129+
    $as_echo_n "(cached) " >&6
    4130+
    else
    4131+
    pgac_save_CFLAGS=$CFLAGS
    4132+
    CFLAGS="$pgac_save_CFLAGS -Wmissing-format-attribute"
    4133+
    ac_save_c_werror_flag=$ac_c_werror_flag
    4134+
    ac_c_werror_flag=yes
    4135+
    cat >conftest.$ac_ext <<_ACEOF
    4136+
    /* confdefs.h. */
    4137+
    _ACEOF
    4138+
    cat confdefs.h >>conftest.$ac_ext
    4139+
    cat >>conftest.$ac_ext <<_ACEOF
    4140+
    /* end confdefs.h. */
    4141+
    4142+
    int
    4143+
    main ()
    4144+
    {
    4145+
    4146+
    ;
    4147+
    return 0;
    4148+
    }
    4149+
    _ACEOF
    4150+
    rm -f conftest.$ac_objext
    4151+
    if { (ac_try="$ac_compile"
    4152+
    case "(($ac_try" in
    4153+
    *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
    4154+
    *) ac_try_echo=$ac_try;;
    4155+
    esac
    4156+
    eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
    4157+
    $as_echo "$ac_try_echo") >&5
    4158+
    (eval "$ac_compile") 2>conftest.er1
    4159+
    ac_status=$?
    4160+
    grep -v '^ *+' conftest.er1 >conftest.err
    4161+
    rm -f conftest.er1
    4162+
    cat conftest.err >&5
    4163+
    $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
    4164+
    (exit $ac_status); } && {
    4165+
    test -z "$ac_c_werror_flag" ||
    4166+
    test ! -s conftest.err
    4167+
    } && test -s conftest.$ac_objext; then
    4168+
    pgac_cv_prog_cc_cflags__Wmissing_format_attribute=yes
    4169+
    else
    4170+
    $as_echo "$as_me: failed program was:" >&5
    4171+
    sed 's/^/| /' conftest.$ac_ext >&5
    4172+
    4173+
    pgac_cv_prog_cc_cflags__Wmissing_format_attribute=no
    4174+
    fi
    4175+
    4176+
    rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
    4177+
    ac_c_werror_flag=$ac_save_c_werror_flag
    4178+
    CFLAGS="$pgac_save_CFLAGS"
    4179+
    fi
    4180+
    { $as_echo "$as_me:$LINENO: result: $pgac_cv_prog_cc_cflags__Wmissing_format_attribute" >&5
    4181+
    $as_echo "$pgac_cv_prog_cc_cflags__Wmissing_format_attribute" >&6; }
    4182+
    if test x"$pgac_cv_prog_cc_cflags__Wmissing_format_attribute" = x"yes"; then
    4183+
    CFLAGS="$CFLAGS -Wmissing-format-attribute"
    4184+
    fi
    4185+
    41264186
    # This was included in -Wall/-Wformat in older GCC versions
    41274187
    { $as_echo "$as_me:$LINENO: checking whether $CC supports -Wformat-security" >&5
    41284188
    $as_echo_n "checking whether $CC supports -Wformat-security... " >&6; }

    configure.in

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -430,6 +430,7 @@ if test "$GCC" = yes -a "$ICC" = no; then
    430430
    # These work in some but not all gcc versions
    431431
    PGAC_PROG_CC_CFLAGS_OPT([-Wdeclaration-after-statement])
    432432
    PGAC_PROG_CC_CFLAGS_OPT([-Wendif-labels])
    433+
    PGAC_PROG_CC_CFLAGS_OPT([-Wmissing-format-attribute])
    433434
    # This was included in -Wall/-Wformat in older GCC versions
    434435
    PGAC_PROG_CC_CFLAGS_OPT([-Wformat-security])
    435436
    # Disable strict-aliasing rules; needed for gcc 3.3+

    contrib/pg_upgrade/info.c

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -286,7 +286,7 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
    286286
    (GET_MAJOR_VERSION(old_cluster.major_version) <= 804) ?
    287287
    "" : ", 'pg_largeobject_metadata', 'pg_largeobject_metadata_oid_index'");
    288288

    289-
    res = executeQueryOrDie(conn, query);
    289+
    res = executeQueryOrDie(conn, "%s", query);
    290290

    291291
    ntups = PQntuples(res);
    292292

    contrib/pg_upgrade/pg_upgrade.h

    Lines changed: 10 additions & 6 deletions
    Original file line numberDiff line numberDiff line change
    @@ -292,8 +292,8 @@ void split_old_dump(void);
    292292

    293293
    /* exec.c */
    294294

    295-
    int exec_prog(bool throw_error,
    296-
    const char *cmd,...);
    295+
    int exec_prog(bool throw_error, const char *cmd, ...)
    296+
    __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
    297297
    void verify_directories(void);
    298298
    bool is_server_running(const char *datadir);
    299299
    void rename_old_pg_control(void);
    @@ -377,7 +377,8 @@ void init_tablespaces(void);
    377377
    /* server.c */
    378378

    379379
    PGconn *connectToServer(ClusterInfo *cluster, const char *db_name);
    380-
    PGresult *executeQueryOrDie(PGconn *conn, const char *fmt,...);
    380+
    PGresult *executeQueryOrDie(PGconn *conn, const char *fmt, ...)
    381+
    __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
    381382

    382383
    void start_postmaster(ClusterInfo *cluster);
    383384
    void stop_postmaster(bool fast);
    @@ -390,9 +391,12 @@ void check_pghost_envvar(void);
    390391
    char *quote_identifier(const char *s);
    391392
    int get_user_info(char **user_name);
    392393
    void check_ok(void);
    393-
    void report_status(eLogType type, const char *fmt,...);
    394-
    void pg_log(eLogType type, char *fmt,...);
    395-
    void prep_status(const char *fmt,...);
    394+
    void report_status(eLogType type, const char *fmt, ...)
    395+
    __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
    396+
    void pg_log(eLogType type, char *fmt, ...)
    397+
    __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
    398+
    void prep_status(const char *fmt, ...)
    399+
    __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
    396400
    void check_ok(void);
    397401
    char *pg_strdup(const char *s);
    398402
    void *pg_malloc(int size);

    contrib/pg_upgrade/relfilenode.c

    Lines changed: 3 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -71,7 +71,9 @@ transfer_all_new_dbs(DbInfoArr *old_db_arr,
    7171
    }
    7272
    }
    7373

    74-
    prep_status(""); /* in case nothing printed */
    74+
    prep_status(" "); /* in case nothing printed; pass a space so gcc
    75+
    * doesn't complain about empty format
    76+
    * string */
    7577
    check_ok();
    7678

    7779
    return msg;

    contrib/pgcrypto/px.h

    Lines changed: 2 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -204,7 +204,8 @@ const char *px_resolve_alias(const PX_Alias *aliases, const char *name);
    204204
    void px_set_debug_handler(void (*handler) (const char *));
    205205

    206206
    #ifdef PX_DEBUG
    207-
    void px_debug(const char *fmt,...);
    207+
    void px_debug(const char *fmt, ...)
    208+
    __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
    208209
    #else
    209210
    #define px_debug(...)
    210211
    #endif

    src/bin/pg_dump/pg_backup_archiver.c

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -119,8 +119,8 @@ static int _discoverArchiveFormat(ArchiveHandle *AH);
    119119

    120120
    static int RestoringToDB(ArchiveHandle *AH);
    121121
    static void dump_lo_buf(ArchiveHandle *AH);
    122-
    static void _write_msg(const char *modulename, const char *fmt, va_list ap);
    123-
    static void _die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt, va_list ap);
    122+
    static void _write_msg(const char *modulename, const char *fmt, va_list ap) __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 0)));
    123+
    static void _die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt, va_list ap) __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 0)));
    124124

    125125
    static void dumpTimestamp(ArchiveHandle *AH, const char *msg, time_t tim);
    126126
    static void SetOutput(ArchiveHandle *AH, char *filename, int compression);

    src/bin/pg_dump/pg_backup_tar.c

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -112,7 +112,7 @@ static void tarClose(ArchiveHandle *AH, TAR_MEMBER *TH);
    112112
    #ifdef __NOT_USED__
    113113
    static char *tarGets(char *buf, size_t len, TAR_MEMBER *th);
    114114
    #endif
    115-
    static int tarPrintf(ArchiveHandle *AH, TAR_MEMBER *th, const char *fmt,...);
    115+
    static int tarPrintf(ArchiveHandle *AH, TAR_MEMBER *th, const char *fmt, ...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
    116116

    117117
    static void _tarAddFile(ArchiveHandle *AH, TAR_MEMBER *th);
    118118
    static int _tarChecksum(char *th);

    src/include/lib/stringinfo.h

    Lines changed: 2 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -105,7 +105,8 @@ __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
    105105
    * without modifying str. Typically the caller would enlarge str and retry
    106106
    * on false return --- see appendStringInfo for standard usage pattern.
    107107
    */
    108-
    extern bool appendStringInfoVA(StringInfo str, const char *fmt, va_list args);
    108+
    extern bool appendStringInfoVA(StringInfo str, const char *fmt, va_list args)
    109+
    __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 0)));
    109110

    110111
    /*------------------------
    111112
    * appendStringInfoString

    src/interfaces/ecpg/ecpglib/descriptor.c

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -388,7 +388,7 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)
    388388
    */
    389389
    if (arrsize > 0 && ntuples > arrsize)
    390390
    {
    391-
    ecpg_log("ECPGget_desc on line %d: incorrect number of matches; %d don't fit into array of %d\n",
    391+
    ecpg_log("ECPGget_desc on line %d: incorrect number of matches; %d don't fit into array of %ld\n",
    392392
    lineno, ntuples, arrsize);
    393393
    ecpg_raise(lineno, ECPG_TOO_MANY_MATCHES, ECPG_SQLSTATE_CARDINALITY_VIOLATION, NULL);
    394394
    return false;
    @@ -457,7 +457,7 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)
    457457
    */
    458458
    if (data_var.ind_arrsize > 0 && ntuples > data_var.ind_arrsize)
    459459
    {
    460-
    ecpg_log("ECPGget_desc on line %d: incorrect number of matches (indicator); %d don't fit into array of %d\n",
    460+
    10000 ecpg_log("ECPGget_desc on line %d: incorrect number of matches (indicator); %d don't fit into array of %ld\n",
    461461
    lineno, ntuples, data_var.ind_arrsize);
    462462
    ecpg_raise(lineno, ECPG_TOO_MANY_MATCHES, ECPG_SQLSTATE_CARDINALITY_VIOLATION, NULL);
    463463
    return false;

    src/interfaces/ecpg/ecpglib/error.c

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -335,7 +335,7 @@ ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat)
    335335
    sqlca->sqlcode = ECPG_PGSQL;
    336336

    337337
    /* %.*s is safe here as long as sqlstate is all-ASCII */
    338-
    ecpg_log("raising sqlstate %.*s (sqlcode %d): %s\n",
    338+
    ecpg_log("raising sqlstate %.*s (sqlcode %ld): %s\n",
    339339
    sizeof(sqlca->sqlstate), sqlca->sqlstate, sqlca->sqlcode, sqlca->sqlerrm.sqlerrmc);
    340340

    341341
    /* free all memory we have allocated for the user */

    src/interfaces/ecpg/ecpglib/execute.c

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -332,7 +332,7 @@ ecpg_store_result(const PGresult *results, int act_field,
    332332
    */
    333333
    if ((var->arrsize > 0 && ntuples > var->arrsize) || (var->ind_arrsize > 0 && ntuples > var->ind_arrsize))
    334334
    {
    335-
    ecpg_log("ecpg_store_result on line %d: incorrect number of matches; %d don't fit into array of %d\n",
    335+
    ecpg_log("ecpg_store_result on line %d: incorrect number of matches; %d don't fit into array of %ld\n",
    336336
    stmt->lineno, ntuples, var->arrsize);
    337337
    ecpg_raise(stmt->lineno, INFORMIX_MODE(stmt->compat) ? ECPG_INFORMIX_SUBSELECT_NOT_ONE : ECPG_TOO_MANY_MATCHES, ECPG_SQLSTATE_CARDINALITY_VIOLATION, NULL);
    338338
    return false;

    src/interfaces/ecpg/ecpglib/extern.h

    Lines changed: 1 addition & 1 deletion
    3EE7
    Original file line numberDiff line numberDiff line change
    @@ -161,7 +161,7 @@ void ecpg_raise(int line, int code, const char *sqlstate, const char *str);
    161161
    void ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat);
    162162
    char *ecpg_prepared(const char *, struct connection *);
    163163
    bool ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection * conn);
    164-
    void ecpg_log(const char *format,...);
    164+
    void ecpg_log(const char *format, ...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
    165165
    bool ecpg_auto_prepare(int, const char *, const int, char **, const char *);
    166166
    void ecpg_init_sqlca(struct sqlca_t * sqlca);
    167167

    0 commit comments

    Comments
     (0)
    0