From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Price Date: Wed, 28 Jan 2015 15:14:43 +0000 Subject: [Cluster-devel] [PATCH 2/3] fsck.gfs2: Simplify bad_journalname In-Reply-To: <1324983030.2636962.1422450781714.JavaMail.zimbra@redhat.com> References: <1422373935-19184-1-git-send-email-anprice@redhat.com> <1422373935-19184-2-git-send-email-anprice@redhat.com> <1324983030.2636962.1422450781714.JavaMail.zimbra@redhat.com> Message-ID: <54C8FCE3.4070408@redhat.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit On 28/01/15 13:13, Bob Peterson wrote: > ----- Original Message ----- >> Remove the need for a temporary string and strncpy call by passing the >> length of the string to printf. >> >> Signed-off-by: Andrew Price >> --- >> gfs2/fsck/initialize.c | 8 ++------ >> 1 file changed, 2 insertions(+), 6 deletions(-) >> >> diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c >> index 1ab078b..c052205 100644 >> --- a/gfs2/fsck/initialize.c >> +++ b/gfs2/fsck/initialize.c >> @@ -1513,14 +1513,10 @@ static int init_rindex(struct gfs2_sbd *sdp) >> >> static void bad_journalname(const char *filename, int len) >> { >> - char tmp_name[64]; >> - >> if (len >= 64) >> len = 63; >> - strncpy(tmp_name, filename, len); >> - tmp_name[len] = '\0'; >> - log_debug(_("Journal index entry '%s' has an invalid filename.\n"), >> - tmp_name); >> + log_debug(_("Journal index entry '%.*s' has an invalid filename.\n"), >> + len, filename); >> } >> >> /** >> -- >> 1.9.3 > > Nice trick (strangely, I've never used that construct), but we could just as well get rid of the whole function altogether. I did consider removing it but, due to if-nesting and being called from two places, it makes things cleaner to leave it in a separate function. When fsck.gfs2 is fast enough that we need to worry about function call overhead then maybe we can inline it :) Thanks, Andy