]> err.no Git - util-linux/commitdiff
blkid: cleanup -u <list> parsing
authorKarel Zak <kzak@redhat.com>
Mon, 22 Mar 2010 14:16:01 +0000 (15:16 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 22 Mar 2010 14:16:01 +0000 (15:16 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/blkid.c

index 1a5db55025147b63721aa2f7877491dec12cc21a..b2d231bc7330e6a475d9a3d807813b8ab3cc49db 100644 (file)
@@ -526,32 +526,41 @@ done:
 static int list_to_usage(const char *list, int *flag)
 {
        int mask = 0;
-       const char *word, *p = list;
+       const char *word = NULL, *p = list;
 
        if (p && strncmp(p, "no", 2) == 0) {
                *flag = BLKID_FLTR_NOTIN;
                p += 2;
        }
 
-       for (word = p; p && *p; p++) {
-               if (*p == ',' || *(p + 1) == '\0') {
-                       if (!strncmp(word, "filesystem", 10))
-                               mask |= BLKID_USAGE_FILESYSTEM;
-                       else if (!strncmp(word, "raid", 4))
-                               mask |= BLKID_USAGE_RAID;
-                       else if (!strncmp(word, "crypto", 6))
-                               mask |= BLKID_USAGE_CRYPTO;
-                       else if (!strncmp(word, "other", 5))
-                               mask |= BLKID_USAGE_OTHER;
-                       else {
-                               fprintf(stderr, "unknown usage keyword '%*s'\n",
-                                               (int) (p - word), word);
-                               exit(4);
-                       }
-                       word = p + 1;
-               }
+       if (!p || !*p)
+               goto err;
+
+       while(p) {
+               word = p;
+
+               p = strchr(p, ',');
+               if (p)
+                       p++;
+
+               if (!strncmp(word, "filesystem", 10))
+                       mask |= BLKID_USAGE_FILESYSTEM;
+               else if (!strncmp(word, "raid", 4))
+                       mask |= BLKID_USAGE_RAID;
+               else if (!strncmp(word, "crypto", 6))
+                       mask |= BLKID_USAGE_CRYPTO;
+               else if (!strncmp(word, "other", 5))
+                       mask |= BLKID_USAGE_OTHER;
+               else
+                       goto err;
        }
        return mask;
+
+err:
+       *flag = 0;
+       fprintf(stderr, "unknown kerword in -u <list> argument: '%s'\n",
+                       word ? word : list);
+       exit(4);
 }
 
 int main(int argc, char **argv)