chiark / gitweb /
fix more compiler warnings ...
authorKay Sievers <kay.sievers@suse.de>
Fri, 12 Aug 2005 22:18:44 +0000 (00:18 +0200)
committerKay Sievers <kay.sievers@suse.de>
Fri, 12 Aug 2005 22:18:44 +0000 (00:18 +0200)
Signed-off-by: Kay Sievers <kay.sievers@suse.de>
extras/scsi_id/scsi_id.c
extras/usb_id/usb_id.c
extras/volume_id/volume_id/util.c
extras/volume_id/volume_id/volume_id.c
udev_db.c
udev_rules.c
udev_utils_run.c

index 8e5172f93c542f150a9800c97565e1832d7b47ad..a46d1b377da97dfd08075a76b37f6ebdc4da0cac 100644 (file)
@@ -133,42 +133,42 @@ static void set_str(char *to, const char *from, size_t count)
        to[j] = '\0';
 }
 
        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;
 {
        int type_num;
        char *eptr;
+       char *type = "generic";
 
        type_num = strtoul(from, &eptr, 0);
        if (eptr != from) {
                switch (type_num) {
                case 0:
 
        type_num = strtoul(from, &eptr, 0);
        if (eptr != from) {
                switch (type_num) {
                case 0:
-                       sprintf(to, "disk");
+                       type = "disk";
                        break;
                case 1:
                        break;
                case 1:
-                       sprintf(to, "tape");
+                       type = "tape";
                        break;
                case 4:
                        break;
                case 4:
-                       sprintf(to, "optical");
+                       type = "optical";
                        break;
                case 5:
                        break;
                case 5:
-                       sprintf(to, "cd");
+                       type = "cd";
                        break;
                case 7:
                        break;
                case 7:
-                       sprintf(to, "optical");
+                       type = "optical";
                        break;
                case 0xe:
                        break;
                case 0xe:
-                       sprintf(to, "disk");
+                       type = "disk";
                        break;
                case 0xf:
                        break;
                case 0xf:
-                       sprintf(to, "optical");
+                       type = "optical";
                        break;
                default:
                        break;
                default:
-                       sprintf(to, "generic");
                        break;
                }
                        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,
 }
 
 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) {
         */
        optind = 1;
        while (1) {
-               option = getopt(argc, argv, short_options);
+               option = getopt(argc, argv, short_opts);
                if (option == -1)
                        break;
 
                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;
        }
                            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) {
 
        type = sysfs_get_device_attr(scsi_dev, "rev");
        if (!type) {
index 37db6d14dbaaf75e0de1bbf276ec8429b8218821..f5ee7959246a8d3a93653497ad0441988915aba7 100644 (file)
@@ -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
  */
  *
  * 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;
 {
        int type_num;
        char *eptr;
+       char *type = "generic";
 
        type_num = strtoul(from, &eptr, 0);
        if (eptr != from) {
                switch (type_num) {
                case 1:
 
        type_num = strtoul(from, &eptr, 0);
        if (eptr != from) {
                switch (type_num) {
                case 1:
-                       sprintf(to, "audio");
+                       type = "audio";
                        break;
                case 3:
                        break;
                case 3:
-                       sprintf(to, "hid");
+                       type = "hid";
                        break;
                case 7:
                        break;
                case 7:
-                       sprintf(to, "printer");
+                       type = "printer";
                        break;
                case 8:
                        break;
                case 8:
-                       sprintf(to, "disk");
+                       type = "disk";
                        break;
                case 2: /* CDC-Control */
                case 5: /* Physical */
                        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:
                case 0xf2: /* Application-specific */
                case 0xff: /* Vendor-specific */
                default:
-                       sprintf(to, "generic");
                        break;
                }
                        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.
  */
  * 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;
 {
        int type_num = 0;
        char *eptr;
+       char *type = "generic";
 
        type_num = strtoul(from, &eptr, 0);
        if (eptr != from) {
                switch (type_num) {
                case 2:
 
        type_num = strtoul(from, &eptr, 0);
        if (eptr != from) {
                switch (type_num) {
                case 2:
-                       sprintf(to, "cd");
+                       type = "cd";
                        break;
                case 3:
                        break;
                case 3:
-                       sprintf(to, "tape");
+                       type = "tape";
                        break;
                case 4: /* UFI */
                case 5: /* SFF-8070i */
                        break;
                case 4: /* UFI */
                case 5: /* SFF-8070i */
-                       sprintf(to, "floppy");
+                       type = "floppy";
                        break;
                case 1: /* RBC devices */
                case 6: /* Transparent SPC-2 devices */
                        break;
                case 1: /* RBC devices */
                case 6: /* Transparent SPC-2 devices */
-                       sprintf(to, "disk");
+                       type = "disk";
+                       break;
+               default:
                        break;
                }
                        break;
                }
-       } else {
-               sprintf(to, "generic");
        }
        }
+       strncpy(to, type, len);
+       to[len-1] = '\0';
 
        return type_num;
 }
 
        return type_num;
 }
index a145a8aa2f207c595f2334b9e0f22ec6661fd53f..868d67306cd594a769e26531f21ae204a3749ef7 100644 (file)
@@ -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;
 }
 
        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;
 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 */
        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;
        while (i--) {
                if (!isspace(id->label[i]))
                        break;
index 4c4a42a00d6ca1902727171fa71c088ea0f8574f..e7d4d75666aeaca6fbd5ff11820cf6c58f404f27 100644 (file)
@@ -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));
 
        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);
 
        /* create tempory node to open the block device */
        unlink(tmp_node);
index f9adf5c6317554b6bb53cc9d24989f879b28a21f..ac5a7e6d653dbf93e70a181eaf869154f7f3d06b 100644 (file)
--- a/udev_db.c
+++ b/udev_db.c
@@ -262,7 +262,7 @@ int udev_db_search_name(char *devpath, size_t len, const char *name)
                                nodename[count-2] = '\0';
                                dbg("compare '%s' '%s'", nodename, name);
                                if (strcmp(nodename, name) == 0) {
                                nodename[count-2] = '\0';
                                dbg("compare '%s' '%s'", nodename, name);
                                if (strcmp(nodename, name) == 0) {
-                                       memcpy(devpath, &bufline[2], count-2);
+                                       strlcpy(devpath, nodename, len);
                                        devpath[count-2] = '\0';
                                        file_unmap(buf, bufsize);
                                        closedir(dir);
                                        devpath[count-2] = '\0';
                                        file_unmap(buf, bufsize);
                                        closedir(dir);
index 40c010c63f97447d24dfd1bb065bf4c9a17c8781..791e98ec07b0788484a348e5f4f3d2bfe924e3a4 100644 (file)
@@ -270,7 +270,7 @@ static int import_parent_into_env(struct udevice *udev, struct sysfs_class_devic
 /* finds the lowest positive N such that <name>N isn't present in the udevdb
  * if <name> doesn't exist, 0 is returned, N otherwise
  */
 /* finds the lowest positive N such that <name>N isn't present in the udevdb
  * if <name> doesn't exist, 0 is returned, N otherwise
  */
-static int find_free_number(struct udevice *udev, const char *name)
+static int find_free_number(const char *name)
 {
        char devpath[PATH_SIZE];
        char filename[PATH_SIZE];
 {
        char devpath[PATH_SIZE];
        char filename[PATH_SIZE];
@@ -397,7 +397,7 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize,
                { .name = "root",               .fmt = 'r',     .type = SUBST_ROOT },
                { .name = "modalias",           .fmt = 'A',     .type = SUBST_MODALIAS },
                { .name = "env",                .fmt = 'E',     .type = SUBST_ENV },
                { .name = "root",               .fmt = 'r',     .type = SUBST_ROOT },
                { .name = "modalias",           .fmt = 'A',     .type = SUBST_MODALIAS },
                { .name = "env",                .fmt = 'E',     .type = SUBST_ENV },
-               {}
+               { NULL, '\0', 0 }
        };
        enum subst_type type;
        const struct subst_map *subst;
        };
        enum subst_type type;
        const struct subst_map *subst;
@@ -546,7 +546,7 @@ found:
                        dbg("substitute sysfs value '%s'", temp2);
                        break;
                case SUBST_ENUM:
                        dbg("substitute sysfs value '%s'", temp2);
                        break;
                case SUBST_ENUM:
-                       next_free_number = find_free_number(udev, string);
+                       next_free_number = find_free_number(string);
                        if (next_free_number > 0) {
                                sprintf(temp2, "%d", next_free_number);
                                strlcat(string, temp2, maxsize);
                        if (next_free_number > 0) {
                                sprintf(temp2, "%d", next_free_number);
                                strlcat(string, temp2, maxsize);
index 50b31781e7f31d6d3f1dfa6ff8f8962cc346ca1c..44fb7f831624c4012c3564f25411a724e3b95ff5 100644 (file)
@@ -164,7 +164,7 @@ int run_program(const char *command, const char *subsystem,
        default:
                /* read from child if requested */
                if (outpipe[0] > 0 || errpipe[0] > 0) {
        default:
                /* read from child if requested */
                if (outpipe[0] > 0 || errpipe[0] > 0) {
-                       size_t count;
+                       ssize_t count;
                        size_t respos = 0;
 
                        /* parent closes child ends of pipes */
                        size_t respos = 0;
 
                        /* parent closes child ends of pipes */