Skip to content

Commit

Permalink
Replace /*PRINTFLIKEn*/ with attribute(printf)
Browse files Browse the repository at this point in the history
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Issue #12201
  • Loading branch information
nabijaczleweli authored and behlendorf committed Jul 26, 2021
1 parent 1373709 commit 5dbf6c5
Show file tree
Hide file tree
Showing 19 changed files with 76 additions and 164 deletions.
2 changes: 1 addition & 1 deletion cmd/zpool/zpool_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void free_vdev_cmd_data_list(vdev_cmd_data_list_t *vcdl);
int check_device(const char *path, boolean_t force,
boolean_t isspare, boolean_t iswholedisk);
boolean_t check_sector_size_database(char *path, int *sector_size);
void vdev_error(const char *fmt, ...);
void vdev_error(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
int check_file(const char *file, boolean_t force, boolean_t isspare);
void after_zpool_upgrade(zpool_handle_t *zhp);

Expand Down
26 changes: 18 additions & 8 deletions cmd/zpool/zpool_vdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
boolean_t error_seen;
boolean_t is_force;

/*PRINTFLIKE1*/
void
vdev_error(const char *fmt, ...)
{
Expand Down Expand Up @@ -704,8 +703,11 @@ get_replication(nvlist_t *nvroot, boolean_t fatal)
"are present\n"),
raidz->zprl_type,
mirror->zprl_type,
(u_longlong_t)
raidz->zprl_parity,
(u_longlong_t)
mirror->zprl_children - 1,
(u_longlong_t)
mirror->zprl_children);
else
return (NULL);
Expand All @@ -728,7 +730,9 @@ get_replication(nvlist_t *nvroot, boolean_t fatal)
"%llu are present\n"),
lastrep.zprl_type,
rep.zprl_type,
(u_longlong_t)
lastrep.zprl_parity,
(u_longlong_t)
rep.zprl_parity);
else
return (NULL);
Expand All @@ -755,8 +759,9 @@ get_replication(nvlist_t *nvroot, boolean_t fatal)
"mismatched replication level: "
"both %llu and %llu device parity "
"%s vdevs are present\n"),
(u_longlong_t)
lastrep.zprl_parity,
rep.zprl_parity,
(u_longlong_t)rep.zprl_parity,
rep.zprl_type);
else
return (NULL);
Expand All @@ -769,7 +774,9 @@ get_replication(nvlist_t *nvroot, boolean_t fatal)
"mismatched replication level: "
"both %llu-way and %llu-way %s "
"vdevs are present\n"),
(u_longlong_t)
lastrep.zprl_children,
(u_longlong_t)
rep.zprl_children,
rep.zprl_type);
else
Expand Down Expand Up @@ -854,9 +861,9 @@ check_replication(nvlist_t *config, nvlist_t *newroot)
"and %s vdevs, %llu vs. %llu (%llu-way)\n"),
raidz->zprl_type,
mirror->zprl_type,
raidz->zprl_parity,
mirror->zprl_children - 1,
mirror->zprl_children);
(u_longlong_t)raidz->zprl_parity,
(u_longlong_t)mirror->zprl_children - 1,
(u_longlong_t)mirror->zprl_children);
ret = -1;
}
} else if (strcmp(current->zprl_type, new->zprl_type) != 0) {
Expand All @@ -869,14 +876,17 @@ check_replication(nvlist_t *config, nvlist_t *newroot)
vdev_error(gettext(
"mismatched replication level: pool uses %llu "
"device parity and new vdev uses %llu\n"),
current->zprl_parity, new->zprl_parity);
(u_longlong_t)current->zprl_parity,
(u_longlong_t)new->zprl_parity);
ret = -1;
} else if (current->zprl_children != new->zprl_children) {
vdev_error(gettext(
"mismatched replication level: pool uses %llu-way "
"%s and new vdev uses %llu-way %s\n"),
current->zprl_children, current->zprl_type,
new->zprl_children, new->zprl_type);
(u_longlong_t)current->zprl_children,
current->zprl_type,
(u_longlong_t)new->zprl_children,
new->zprl_type);
ret = -1;
}
}
Expand Down
25 changes: 14 additions & 11 deletions include/libuutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,18 @@ const char *uu_strerror(uint32_t);
extern void uu_alt_exit(int);
extern const char *uu_setpname(char *);
extern const char *uu_getpname(void);
/*PRINTFLIKE1*/
extern void uu_warn(const char *, ...);
extern void uu_vwarn(const char *, va_list);
/*PRINTFLIKE1*/
extern void uu_die(const char *, ...) __NORETURN;
extern void uu_vdie(const char *, va_list) __NORETURN;
/*PRINTFLIKE2*/
extern void uu_xdie(int, const char *, ...) __NORETURN;
extern void uu_vxdie(int, const char *, va_list) __NORETURN;
extern void uu_warn(const char *, ...)
__attribute__((format(printf, 1, 2)));
extern void uu_vwarn(const char *, va_list)
__attribute__((format(printf, 1, 0)));
extern void uu_die(const char *, ...)
__attribute__((format(printf, 1, 2))) __NORETURN;
extern void uu_vdie(const char *, va_list)
__attribute__((format(printf, 1, 0))) __NORETURN;
extern void uu_xdie(int, const char *, ...)
__attribute__((format(printf, 2, 3))) __NORETURN;
extern void uu_vxdie(int, const char *, va_list)
__attribute__((format(printf, 2, 0))) __NORETURN;

/*
* Exit status functions (not to be used directly)
Expand All @@ -111,8 +114,8 @@ int uu_check_name(const char *, uint_t);
*/
#define UU_NELEM(a) (sizeof (a) / sizeof ((a)[0]))

/*PRINTFLIKE1*/
extern char *uu_msprintf(const char *format, ...);
extern char *uu_msprintf(const char *format, ...)
__attribute__((format(printf, 1, 2)));
extern void *uu_zalloc(size_t);
extern char *uu_strdup(const char *);
extern void uu_free(void *);
Expand Down
3 changes: 1 addition & 2 deletions include/libuutil_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ extern "C" {
void uu_set_error(uint_t);


/*PRINTFLIKE1*/
void uu_panic(const char *format, ...);
void uu_panic(const char *format, ...) __attribute__((format(printf, 1, 2)));


/*
Expand Down
85 changes: 0 additions & 85 deletions include/os/freebsd/spl/sys/ccompile.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,91 +36,6 @@
extern "C" {
#endif

/*
* Allow for version tests for compiler bugs and features.
*/
#if defined(__GNUC__)
#define __GNUC_VERSION \
(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#else
#define __GNUC_VERSION 0
#endif

#if defined(__ATTRIBUTE_IMPLEMENTED) || defined(__GNUC__)

#if 0
/*
* analogous to lint's PRINTFLIKEn
*/
#define __sun_attr___PRINTFLIKE__(__n) \
__attribute__((__format__(printf, __n, (__n)+1)))
#define __sun_attr___VPRINTFLIKE__(__n) \
__attribute__((__format__(printf, __n, 0)))

#define __sun_attr___KPRINTFLIKE__ __sun_attr___PRINTFLIKE__
#define __sun_attr___KVPRINTFLIKE__ __sun_attr___VPRINTFLIKE__
#else
/*
* Currently the openzfs codebase has a lot of formatting errors
* which are not picked up in the linux build because they're not
* doing formatting checks. LLVM's kprintf implementation doesn't
* actually do format checks!
*
* For FreeBSD these break under gcc! LLVM shim'ed cmn_err as a
* format attribute but also didn't check anything. If one
* replaces it with the above, all of the format issues
* in the codebase show up.
*
* Once those format string issues are addressed, the above
* should be flipped on once again.
*/
#define __sun_attr___PRINTFLIKE__(__n)
#define __sun_attr___VPRINTFLIKE__(__n)
#define __sun_attr___KPRINTFLIKE__(__n)
#define __sun_attr___KVPRINTFLIKE__(__n)

#endif

/*
* This one's pretty obvious -- the function never returns
*/
#define __sun_attr___noreturn__ __attribute__((__noreturn__))

/*
* This is an appropriate label for functions that do not
* modify their arguments, e.g. strlen()
*/
#define __sun_attr___pure__ __attribute__((__pure__))

/*
* This is a stronger form of __pure__. Can be used for functions
* that do not modify their arguments and don't depend on global
* memory.
*/
#define __sun_attr___const__ __attribute__((__const__))

/*
* structure packing like #pragma pack(1)
*/
#define __sun_attr___packed__ __attribute__((__packed__))

#define ___sun_attr_inner(__a) __sun_attr_##__a
#define __sun_attr__(__a) ___sun_attr_inner __a

#else /* __ATTRIBUTE_IMPLEMENTED || __GNUC__ */

#define __sun_attr__(__a)

#endif /* __ATTRIBUTE_IMPLEMENTED || __GNUC__ */

/*
* Shorthand versions for readability
*/

#define __PRINTFLIKE(__n) __sun_attr__((__PRINTFLIKE__(__n)))
#define __VPRINTFLIKE(__n) __sun_attr__((__VPRINTFLIKE__(__n)))
#define __KPRINTFLIKE(__n) __sun_attr__((__KPRINTFLIKE__(__n)))
#define __KVPRINTFLIKE(__n) __sun_attr__((__KVPRINTFLIKE__(__n)))
#if defined(_KERNEL) || defined(_STANDALONE)
#define __NORETURN __sun_attr__((__noreturn__))
#endif /* _KERNEL || _STANDALONE */
Expand Down
23 changes: 8 additions & 15 deletions include/os/freebsd/spl/sys/cmn_err.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,36 +49,29 @@ extern "C" {

#ifndef _ASM

/*PRINTFLIKE2*/
extern void cmn_err(int, const char *, ...)
__KPRINTFLIKE(2);
__attribute__((format(printf, 2, 3)));

extern void vzcmn_err(zoneid_t, int, const char *, __va_list)
__KVPRINTFLIKE(3);
__attribute__((format(printf, 3, 0)));

extern void vcmn_err(int, const char *, __va_list)
__KVPRINTFLIKE(2);
__attribute__((format(printf, 2, 0)));

/*PRINTFLIKE3*/
extern void zcmn_err(zoneid_t, int, const char *, ...)
__KPRINTFLIKE(3);
__attribute__((format(printf, 3, 4)));

extern void vzprintf(zoneid_t, const char *, __va_list)
__KVPRINTFLIKE(2);
__attribute__((format(printf, 2, 0)));

/*PRINTFLIKE2*/
extern void zprintf(zoneid_t, const char *, ...)
__KPRINTFLIKE(2);
__attribute__((format(printf, 2, 3)));

extern void vuprintf(const char *, __va_list)
__KVPRINTFLIKE(1);
__attribute__((format(printf, 1, 0)));

/*PRINTFLIKE1*/
extern void panic(const char *, ...)
__KPRINTFLIKE(1) __NORETURN;

extern void vpanic(const char *, __va_list)
__KVPRINTFLIKE(1) __NORETURN;
__attribute__((format(printf, 1, 2))) __NORETURN;

#endif /* !_ASM */

Expand Down
9 changes: 6 additions & 3 deletions include/os/linux/spl/sys/cmn_err.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@
#define CE_PANIC 3 /* panic */
#define CE_IGNORE 4 /* print nothing */

extern void cmn_err(int, const char *, ...);
extern void vcmn_err(int, const char *, va_list);
extern void vpanic(const char *, va_list);
extern void cmn_err(int, const char *, ...)
__attribute__((format(printf, 2, 3)));
extern void vcmn_err(int, const char *, va_list)
__attribute__((format(printf, 2, 0)));
extern void vpanic(const char *, va_list)
__attribute__((format(printf, 1, 0)));

#define fm_panic panic

Expand Down
6 changes: 4 additions & 2 deletions include/sys/spa.h
Original file line number Diff line number Diff line change
Expand Up @@ -1056,8 +1056,10 @@ extern uint64_t spa_dirty_data(spa_t *spa);
extern spa_autotrim_t spa_get_autotrim(spa_t *spa);

/* Miscellaneous support routines */
extern void spa_load_failed(spa_t *spa, const char *fmt, ...);
extern void spa_load_note(spa_t *spa, const char *fmt, ...);
extern void spa_load_failed(spa_t *spa, const char *fmt, ...)
__attribute__((format(printf, 2, 3)));
extern void spa_load_note(spa_t *spa, const char *fmt, ...)
__attribute__((format(printf, 2, 3)));
extern void spa_activate_mos_feature(spa_t *spa, const char *feature,
dmu_tx_t *tx);
extern void spa_deactivate_mos_feature(spa_t *spa, const char *feature);
Expand Down
3 changes: 2 additions & 1 deletion include/sys/vdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ extern int zfs_nocacheflush;

typedef boolean_t vdev_open_children_func_t(vdev_t *vd);

extern void vdev_dbgmsg(vdev_t *vd, const char *fmt, ...);
extern void vdev_dbgmsg(vdev_t *vd, const char *fmt, ...)
__attribute__((format(printf, 2, 3)));
extern void vdev_dbgmsg_print_tree(vdev_t *, int);
extern int vdev_open(vdev_t *);
extern void vdev_open_children(vdev_t *);
Expand Down
14 changes: 4 additions & 10 deletions lib/libuutil/uu_pname.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
#include <wchar.h>
#include <unistd.h>

static const char PNAME_FMT[] = "%s: ";
static const char ERRNO_FMT[] = ": %s\n";

static const char *pname;

static void
Expand Down Expand Up @@ -85,16 +82,16 @@ uu_alt_exit(int profile)
}
}

static void
static __attribute__((format(printf, 2, 0))) void
uu_warn_internal(int err, const char *format, va_list alist)
{
if (pname != NULL)
(void) fprintf(stderr, PNAME_FMT, pname);
(void) fprintf(stderr, "%s: ", pname);

(void) vfprintf(stderr, format, alist);

if (strrchr(format, '\n') == NULL)
(void) fprintf(stderr, ERRNO_FMT, strerror(err));
(void) fprintf(stderr, ": %s\n", strerror(err));
}

void
Expand All @@ -103,7 +100,6 @@ uu_vwarn(const char *format, va_list alist)
uu_warn_internal(errno, format, alist);
}

/*PRINTFLIKE1*/
void
uu_warn(const char *format, ...)
{
Expand All @@ -113,7 +109,7 @@ uu_warn(const char *format, ...)
va_end(alist);
}

static void
static __attribute__((format(printf, 2, 0))) __NORETURN void
uu_die_internal(int status, const char *format, va_list alist)
{
uu_warn_internal(errno, format, alist);
Expand All @@ -137,7 +133,6 @@ uu_vdie(const char *format, va_list alist)
uu_die_internal(UU_EXIT_FATAL, format, alist);
}

/*PRINTFLIKE1*/
void
uu_die(const char *format, ...)
{
Expand All @@ -153,7 +148,6 @@ uu_vxdie(int status, const char *format, va_list alist)
uu_die_internal(status, format, alist);
}

/*PRINTFLIKE2*/
void
uu_xdie(int status, const char *format, ...)
{
Expand Down
Loading

0 comments on commit 5dbf6c5

Please sign in to comment.