diff options
author | Alan Jenkins <alan-jenkins@tuffmail.co.uk> | 2008-10-21 22:42:15 +0100 |
---|---|---|
committer | Kay Sievers <kay.sievers@vrfy.org> | 2008-10-21 23:55:13 +0200 |
commit | 111e4f81ff057fd5869d152a503ad982e2116f85 (patch) | |
tree | 5b8548f6c41f3b58ff615b43b8cfc76124ade155 /extras/scsi_id | |
parent | 9a23e9e7754027775f62baec847b46703e20d166 (diff) |
replace strncpy() with strlcpy()
The problem was strncpy() doesn't stop after writing the terminating
NUL; by definition it goes on to zero the entire buffer.
I spy another use of strncpy in udev_device_add_property_from_string(),
which is responsible for another ~1% user cpu time...
Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
Diffstat (limited to 'extras/scsi_id')
-rw-r--r-- | extras/scsi_id/scsi_id.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/extras/scsi_id/scsi_id.c b/extras/scsi_id/scsi_id.c index 6334af386b..86c76cfcc4 100644 --- a/extras/scsi_id/scsi_id.c +++ b/extras/scsi_id/scsi_id.c @@ -135,8 +135,7 @@ static void set_type(char *to, const char *from, size_t len) break; } } - strncpy(to, type, len); - to[len-1] = '\0'; + util_strlcpy(to, type, len); } /* @@ -385,8 +384,7 @@ static int set_options(struct udev *udev, case 'd': dev_specified = 1; - strncpy(maj_min_dev, optarg, MAX_PATH_LEN); - maj_min_dev[MAX_PATH_LEN-1] = '\0'; + util_strlcpy(maj_min_dev, optarg, MAX_PATH_LEN); break; case 'e': @@ -394,8 +392,7 @@ static int set_options(struct udev *udev, break; case 'f': - strncpy(config_file, optarg, MAX_PATH_LEN); - config_file[MAX_PATH_LEN-1] = '\0'; + util_strlcpy(config_file, optarg, MAX_PATH_LEN); break; case 'g': @@ -461,8 +458,7 @@ static int set_options(struct udev *udev, } if (optind < argc && !dev_specified) { dev_specified = 1; - strncpy(maj_min_dev, argv[optind], MAX_PATH_LEN); - maj_min_dev[MAX_PATH_LEN-1] = '\0'; + util_strlcpy(maj_min_dev, argv[optind], MAX_PATH_LEN); } return 0; } |