[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] maint: replace a use of strcpy in chmod.c with memcpy
From: |
Jim Meyering |
Subject: |
[PATCH] maint: replace a use of strcpy in chmod.c with memcpy |
Date: |
Mon, 16 Apr 2012 17:45:38 +0200 |
This is on the edge...
I generally prefer to use memcpy when the length is already computed,
so I propose to do that here. However, this is certainly not
performance sensitive, and the strcpy invocation is slightly simpler
and hence a little more readable. Opinions?
>From 31f19d681f91347f0f4b9d4ed148b6aed996bf7e Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Mon, 16 Apr 2012 15:12:02 +0200
Subject: [PATCH] maint: replace a use of strcpy in chmod.c with memcpy
* src/chmod.c (main): Use memcpy rather than strcpy,
since we already have the length handy.
---
src/chmod.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/chmod.c b/src/chmod.c
index aa4ac77..a54078c 100644
--- a/src/chmod.c
+++ b/src/chmod.c
@@ -466,19 +466,19 @@ main (int argc, char **argv)
size_t arg_len = strlen (arg);
size_t mode_comma_len = mode_len + !!mode_len;
size_t new_mode_len = mode_comma_len + arg_len;
if (mode_alloc <= new_mode_len)
{
mode_alloc = new_mode_len + 1;
mode = X2REALLOC (mode, &mode_alloc);
}
mode[mode_len] = ',';
- strcpy (mode + mode_comma_len, arg);
+ memcpy (mode + mode_comma_len, arg, arg_len + 1);
mode_len = new_mode_len;
diagnose_surprises = true;
}
break;
case NO_PRESERVE_ROOT:
preserve_root = false;
break;
case PRESERVE_ROOT:
--
1.7.10.169.g146fe
- [PATCH] maint: replace a use of strcpy in chmod.c with memcpy,
Jim Meyering <=