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 <[email protected]>
---
  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

Reply via email to