Author: marius
Date: Wed May 14 15:22:42 2014
New Revision: 266028
URL: http://svnweb.freebsd.org/changeset/base/266028

Log:
  MFC: r204665
  
  - Make function of finding an available drive name a macro.
  - Move check of /dev/ prefix and copy into a function to save code 
duplication.
    This also fixes a bug where the /dev/ prefix could not be used when creating
    volumes on the command line.
  
  MFC: r209051
  
  Initialize variables before usage.
  
  Found by:     clang static analyzer
  Found by:     Coverity Prevent[tm] (CID 7736, 7760)
  
  MFC: r215704
  
  Fix some more warnings found by clang.
  
  MFC: r229915
  
  Fix warning when compiling with gcc46.

Modified:
  stable/8/sbin/gvinum/gvinum.c
Directory Properties:
  stable/8/sbin/gvinum/   (props changed)

Modified: stable/8/sbin/gvinum/gvinum.c
==============================================================================
--- stable/8/sbin/gvinum/gvinum.c       Wed May 14 15:22:08 2014        
(r266027)
+++ stable/8/sbin/gvinum/gvinum.c       Wed May 14 15:22:42 2014        
(r266028)
@@ -84,8 +84,9 @@ void  printconfig(FILE *, char *);
 char   *create_drive(char *);
 void    create_volume(int, char **, char *);
 char   *find_name(const char *, int, int);
-char   *find_drive(const char *);
 char   *find_pattern(char *, char *);
+void    copy_device(struct gv_drive *, const char *);
+#define find_drive() find_name("gvinumdrive", GV_TYPE_DRIVE, GV_MAXDRIVENAME)
 
 int
 main(int argc, char **argv)
@@ -425,7 +426,7 @@ create_drive(char *device)
        drives = 1;
        dname = NULL;
 
-       drivename = find_drive(device);
+       drivename = find_drive();
        if (drivename == NULL)
                return (NULL);
 
@@ -437,7 +438,7 @@ create_drive(char *device)
                err(1, "unable to allocate for gv_drive object");
 
        strlcpy(d->name, drivename, sizeof(d->name));
-       strlcpy(d->device, device, sizeof(d->device));
+       copy_device(d, device);
        gctl_ro_param(req, "drive0", sizeof(*d), d);
        gctl_ro_param(req, "flags", sizeof(int), &flags);
        gctl_ro_param(req, "drives", sizeof(int), &drives);
@@ -627,14 +628,13 @@ find_name(const char *prefix, int type, 
        return (NULL);
 }
 
-char *
-find_drive(const char *device)
+void
+copy_device(struct gv_drive *d, const char *device)
 {
-
-       /* Strip possible /dev/ in front. */
        if (strncmp(device, "/dev/", 5) == 0)
-               device += 5;
-       return (find_name("gvinumdrive", GV_TYPE_DRIVE, GV_MAXDRIVENAME));
+               strlcpy(d->device, (device + 5), sizeof(d->device));
+       else
+               strlcpy(d->device, device, sizeof(d->device));
 }
 
 /* Detach a plex or subdisk from its parent. */
@@ -645,6 +645,7 @@ gvinum_detach(int argc, char **argv)
        struct gctl_req *req;
        int flags, i;
 
+       flags = 0;
        optreset = 1;
        optind = 1;
        while ((i = getopt(argc, argv, "f")) != -1) {
@@ -936,14 +937,12 @@ gvinum_parityop(int argc, char **argv, i
        struct gctl_req *req;
        int flags, i;
        const char *errstr;
-       char *op, *msg;
+       char *op;
 
        if (rebuild) {
                op = "rebuildparity";
-               msg = "Rebuilding";
        } else {
                op = "checkparity";
-               msg = "Checking";
        }
 
        optreset = 1;
@@ -1056,9 +1055,8 @@ gvinum_rm(int argc, char **argv)
        struct gctl_req *req;
        int flags, i, j;
        const char *errstr;
-       char buf[20], *cmd;
+       char buf[20];
 
-       cmd = argv[0];
        flags = 0;
        optreset = 1;
        optind = 1;
@@ -1291,7 +1289,7 @@ gvinum_grow(int argc, char **argv)
                return;
        }
        /* Lookup device and set an appropriate drive name. */
-       drive = find_drive(argv[2]);
+       drive = find_drive();
        if (drive == NULL) {
                warn("unable to find an appropriate drive name");
                free(s);
@@ -1299,10 +1297,8 @@ gvinum_grow(int argc, char **argv)
                return;
        }
        strlcpy(d->name, drive, sizeof(d->name));
-       if (strncmp(argv[2], "/dev/", 5) == 0)
-               strlcpy(d->device, (argv[2] + 5), sizeof(d->device));
-       else
-               strlcpy(d->device, argv[2], sizeof(d->device));
+       copy_device(d, argv[2]);
+
        drives = 1;
 
        /* We try to use the plex name as basis for the subdisk name. */
@@ -1444,5 +1440,5 @@ printconfig(FILE *of, char *comment)
        if (*comment != '\0')
            fprintf(of, "# Current configuration:\n");
 
-       fprintf(of, buf);
+       fprintf(of, "%s", buf);
 }
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to