diff options
author | Kay Sievers <kay.sievers@suse.de> | 2005-08-13 00:18:44 +0200 |
---|---|---|
committer | Kay Sievers <kay.sievers@suse.de> | 2005-08-13 00:18:44 +0200 |
commit | 853ccc433c4d45c3e1da4336f87b458ed10311ca (patch) | |
tree | 383ab125c708528adc2b3eef110915552189f984 /extras | |
parent | d2e8d41b9c7bacd8169c4cb1d15b7bc95445d34b (diff) |
fix more compiler warnings ...
Signed-off-by: Kay Sievers <kay.sievers@suse.de>
Diffstat (limited to 'extras')
-rw-r--r-- | extras/scsi_id/scsi_id.c | 26 | ||||
-rw-r--r-- | extras/usb_id/usb_id.c | 33 | ||||
-rw-r--r-- | extras/volume_id/volume_id/util.c | 8 | ||||
-rw-r--r-- | extras/volume_id/volume_id/volume_id.c | 2 |
4 files changed, 33 insertions, 36 deletions
diff --git a/extras/scsi_id/scsi_id.c b/extras/scsi_id/scsi_id.c index 8e5172f93c..a46d1b377d 100644 --- a/extras/scsi_id/scsi_id.c +++ b/extras/scsi_id/scsi_id.c @@ -133,42 +133,42 @@ static void set_str(char *to, const char *from, size_t count) to[j] = '\0'; } -static void set_type(char *to, const char *from, int count) +static void set_type(char *to, const char *from, size_t len) { int type_num; char *eptr; + char *type = "generic"; type_num = strtoul(from, &eptr, 0); if (eptr != from) { switch (type_num) { case 0: - sprintf(to, "disk"); + type = "disk"; break; case 1: - sprintf(to, "tape"); + type = "tape"; break; case 4: - sprintf(to, "optical"); + type = "optical"; break; case 5: - sprintf(to, "cd"); + type = "cd"; break; case 7: - sprintf(to, "optical"); + type = "optical"; break; case 0xe: - sprintf(to, "disk"); + type = "disk"; break; case 0xf: - sprintf(to, "optical"); + type = "optical"; break; default: - sprintf(to, "generic"); break; } - } else { - sprintf(to, "generic"); } + strncpy(to, type, len); + to[len-1] = '\0'; } static int get_major_minor(struct sysfs_class_device *class_dev, int *maj, @@ -475,7 +475,7 @@ static int set_options(int argc, char **argv, const char *short_opts, */ optind = 1; while (1) { - option = getopt(argc, argv, short_options); + option = getopt(argc, argv, short_opts); if (option == -1) break; @@ -601,7 +601,7 @@ static int per_dev_options(struct sysfs_device *scsi_dev, int *good_bad, scsi_dev->name); return -1; } - set_type(type_str, type->value, sizeof(type_str)-1); + set_type(type_str, type->value, sizeof(type_str)); type = sysfs_get_device_attr(scsi_dev, "rev"); if (!type) { diff --git a/extras/usb_id/usb_id.c b/extras/usb_id/usb_id.c index 37db6d14db..f5ee795924 100644 --- a/extras/usb_id/usb_id.c +++ b/extras/usb_id/usb_id.c @@ -119,25 +119,26 @@ static void set_str(char *to, const char *from, size_t count) * * Set the type based on the USB interface class */ -static void set_usb_iftype(char *to, const char *from, int count) +static void set_usb_iftype(char *to, const char *from, size_t len) { int type_num; char *eptr; + char *type = "generic"; type_num = strtoul(from, &eptr, 0); if (eptr != from) { switch (type_num) { case 1: - sprintf(to, "audio"); + type = "audio"; break; case 3: - sprintf(to, "hid"); + type = "hid"; break; case 7: - sprintf(to, "printer"); + type = "printer"; break; case 8: - sprintf(to, "disk"); + type = "disk"; break; case 2: /* CDC-Control */ case 5: /* Physical */ @@ -152,12 +153,11 @@ static void set_usb_iftype(char *to, const char *from, int count) case 0xf2: /* Application-specific */ case 0xff: /* Vendor-specific */ default: - sprintf(to, "generic"); break; } - } else { - sprintf(to, "generic"); } + strncpy(to, type, len); + to[len-1] = '\0'; } /* @@ -166,32 +166,35 @@ static void set_usb_iftype(char *to, const char *from, int count) * Set the type base on the interfaceSubClass. * Valid for Mass-Storage devices (type 8) only. */ -static int set_usb_ifsubtype(char *to, const char *from, int count) +static int set_usb_ifsubtype(char *to, const char *from, size_t len) { int type_num = 0; char *eptr; + char *type = "generic"; type_num = strtoul(from, &eptr, 0); if (eptr != from) { switch (type_num) { case 2: - sprintf(to, "cd"); + type = "cd"; break; case 3: - sprintf(to, "tape"); + type = "tape"; break; case 4: /* UFI */ case 5: /* SFF-8070i */ - sprintf(to, "floppy"); + type = "floppy"; break; case 1: /* RBC devices */ case 6: /* Transparent SPC-2 devices */ - sprintf(to, "disk"); + type = "disk"; + break; + default: break; } - } else { - sprintf(to, "generic"); } + strncpy(to, type, len); + to[len-1] = '\0'; return type_num; } diff --git a/extras/volume_id/volume_id/util.c b/extras/volume_id/volume_id/util.c index a145a8aa2f..868d67306c 100644 --- a/extras/volume_id/volume_id/util.c +++ b/extras/volume_id/volume_id/util.c @@ -114,12 +114,6 @@ void volume_id_set_label_raw(struct volume_id *id, const uint8_t *buf, size_t co id->label_raw_len = count; } -static size_t my_strnlen(const char *s, size_t max) { - const char *p = s; - for (; *p && max--; ++p); - return(p - s); -} - void volume_id_set_label_string(struct volume_id *id, const uint8_t *buf, size_t count) { unsigned int i; @@ -127,7 +121,7 @@ void volume_id_set_label_string(struct volume_id *id, const uint8_t *buf, size_t memcpy(id->label, buf, count); /* remove trailing whitespace */ - i = my_strnlen(id->label, count); + i = strnlen(id->label, count); while (i--) { if (!isspace(id->label[i])) break; diff --git a/extras/volume_id/volume_id/volume_id.c b/extras/volume_id/volume_id/volume_id.c index 4c4a42a00d..e7d4d75666 100644 --- a/extras/volume_id/volume_id/volume_id.c +++ b/extras/volume_id/volume_id/volume_id.c @@ -227,7 +227,7 @@ struct volume_id *volume_id_open_dev_t(dev_t devt) snprintf(tmp_node, VOLUME_ID_PATH_MAX, "/dev/.volume_id-%u-%u-%u", getpid(), major(devt), minor(devt)); - tmp_node[VOLUME_ID_PATH_MAX] = '\0'; + tmp_node[VOLUME_ID_PATH_MAX-1] = '\0'; /* create tempory node to open the block device */ unlink(tmp_node); |