diff options
author | Andreas Dilger <adilger@dilger.ca> | 2020-01-14 14:42:18 -0700 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2020-01-24 23:06:58 -0500 |
commit | bc56227376223c02b16703691fd0de6929a1036b (patch) | |
tree | 152c8394b763419a418e0c68fc1bab20e0367d7f /lib/support | |
parent | 6b430d60caf6c4080bd32783659a819425657b69 (diff) | |
download | e2fsprogs-bc56227376223c02b16703691fd0de6929a1036b.tar.gz |
mmp: abstract out repeated 'sizeof(buf), buf' usage
The printf("%.*s") format requires both the buffer size and buffer
pointer to be specified for each use. Since this is repeatedly given
as "(int)sizeof(buf), (char *)buf" for mmp_nodename and mmp_bdevname
fields, with typecasts to avoid compiler warnings.
Add a helper macro EXT2_LEN_STR() to avoid repeated boilerplate code.
This can also be used for other superblock buffer fields that may not
have NUL-terminated strings (e.g. s_volume_name, s_last_mounted,
s_{first,last}_error_func, s_mount_opts) to simplify code and avoid
the need for temporary buffers for NUL-termination.
Annotate the superblock string fields that may not be NUL-terminated.
Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'lib/support')
-rw-r--r-- | lib/support/plausible.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/lib/support/plausible.c b/lib/support/plausible.c index a7268980..024f205e 100644 --- a/lib/support/plausible.c +++ b/lib/support/plausible.c @@ -101,7 +101,6 @@ static void print_ext2_info(const char *device) ext2_filsys fs; errcode_t retval; time_t tm; - char buf[80]; retval = ext2fs_open2(device, 0, EXT2_FLAG_64BITS, 0, 0, unix_io_manager, &fs); @@ -111,13 +110,10 @@ static void print_ext2_info(const char *device) if (sb->s_mtime) { tm = sb->s_mtime; - if (sb->s_last_mounted[0]) { - memset(buf, 0, sizeof(buf)); - strncpy(buf, sb->s_last_mounted, - sizeof(sb->s_last_mounted)); - printf(_("\tlast mounted on %s on %s"), buf, - ctime(&tm)); - } else + if (sb->s_last_mounted[0]) + printf(_("\tlast mounted on %.*s on %s"), + EXT2_LEN_STR(sb->s_last_mounted), ctime(&tm)); + else printf(_("\tlast mounted on %s"), ctime(&tm)); } else if (sb->s_mkfs_time) { tm = sb->s_mkfs_time; |