Skip to content

Commit ffddb4d

Browse files
behlendorfnedbass
authored andcommitted
Fix gcc -Warray-bounds check for dump_object() in zdb
As of gcc 6.1.1 20160621 (Red Hat 6.1.1-3) an array bounds warnings is detected in the zdb the dump_object() function. The analysis is correct but difficult to interpret because this is implemented as a macro. Rework the ZDB_OT_NAME in to a function and remove the case detected by gcc which is a side effect of the DMU_OT_IS_VALID() macro. zdb.c: In function ‘dump_object’: zdb.c:1931:288: error: array subscript is outside array bounds [-Werror=array-bounds] Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Gvozden Neskovic <neskovic@gmail.com> Closes #4907
1 parent 8fe1fb1 commit ffddb4d

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

cmd/zdb/zdb.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,22 @@
6767
zio_compress_table[(idx)].ci_name : "UNKNOWN")
6868
#define ZDB_CHECKSUM_NAME(idx) ((idx) < ZIO_CHECKSUM_FUNCTIONS ? \
6969
zio_checksum_table[(idx)].ci_name : "UNKNOWN")
70-
#define ZDB_OT_NAME(idx) ((idx) < DMU_OT_NUMTYPES ? \
71-
dmu_ot[(idx)].ot_name : DMU_OT_IS_VALID(idx) ? \
72-
dmu_ot_byteswap[DMU_OT_BYTESWAP(idx)].ob_name : "UNKNOWN")
7370
#define ZDB_OT_TYPE(idx) ((idx) < DMU_OT_NUMTYPES ? (idx) : \
7471
(((idx) == DMU_OTN_ZAP_DATA || (idx) == DMU_OTN_ZAP_METADATA) ? \
7572
DMU_OT_ZAP_OTHER : DMU_OT_NUMTYPES))
7673

74+
static char *
75+
zdb_ot_name(dmu_object_type_t type)
76+
{
77+
if (type < DMU_OT_NUMTYPES)
78+
return (dmu_ot[type].ot_name);
79+
else if ((type & DMU_OT_NEWTYPE) &&
80+
((type & DMU_OT_BYTESWAP_MASK) < DMU_BSWAP_NUMFUNCS))
81+
return (dmu_ot_byteswap[type & DMU_OT_BYTESWAP_MASK].ob_name);
82+
else
83+
return ("UNKNOWN");
84+
}
85+
7786
#ifndef lint
7887
extern int zfs_recover;
7988
extern uint64_t zfs_arc_max, zfs_arc_meta_limit;
@@ -1925,12 +1934,12 @@ dump_object(objset_t *os, uint64_t object, int verbosity, int *print_header)
19251934

19261935
(void) printf("%10lld %3u %5s %5s %5s %5s %6s %s%s\n",
19271936
(u_longlong_t)object, doi.doi_indirection, iblk, dblk,
1928-
asize, lsize, fill, ZDB_OT_NAME(doi.doi_type), aux);
1937+
asize, lsize, fill, zdb_ot_name(doi.doi_type), aux);
19291938

19301939
if (doi.doi_bonus_type != DMU_OT_NONE && verbosity > 3) {
19311940
(void) printf("%10s %3s %5s %5s %5s %5s %6s %s\n",
19321941
"", "", "", "", "", bonus_size, "bonus",
1933-
ZDB_OT_NAME(doi.doi_bonus_type));
1942+
zdb_ot_name(doi.doi_bonus_type));
19341943
}
19351944

19361945
if (verbosity >= 4) {

0 commit comments

Comments
 (0)