]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
misc: replace magic number 37 with UUID_STR_LEN
authorPhilip Prindeville <philipp@redfish-solutions.com>
Mon, 28 Aug 2017 19:20:55 +0000 (13:20 -0600)
committerKarel Zak <kzak@redhat.com>
Tue, 5 Sep 2017 09:49:21 +0000 (11:49 +0200)
Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
14 files changed:
disk-utils/mkswap.c
libblkid/src/partitions/dos.c
libblkid/src/partitions/partitions.c
libblkid/src/partitions/partitions.h
libblkid/src/superblocks/superblocks.c
libblkid/src/superblocks/superblocks.h
libfdisk/src/gpt.c
libuuid/src/test_uuid.c
libuuid/src/uuid.h
misc-utils/test_uuidd.c
misc-utils/uuidd.c
misc-utils/uuidgen.c
sys-utils/swapon.c
tests/helpers/test_uuid_namespace.c

index 748e241cf97dc9109c125093d663c9220b1ab894..a6077daf09dbf981be8363879395064248d9bd05 100644 (file)
@@ -132,7 +132,7 @@ static void set_uuid_and_label(const struct mkswap_control *ctl)
                        printf(_("no label, "));
 #ifdef HAVE_LIBUUID
                if (ctl->uuid) {
-                       char uuid_string[37];
+                       char uuid_string[UUID_STR_LEN];
                        uuid_unparse(ctl->uuid, uuid_string);
                        printf("UUID=%s\n", uuid_string);
                } else
index 30e3e9e732041532f88c233c1b681d8c76258328..1db238781013d0a14cee18d87665f6275a58f9cc 100644 (file)
@@ -177,7 +177,7 @@ static int probe_dos_pt(blkid_probe pr,
        struct dos_partition *p0, *p;
        unsigned char *data;
        uint32_t start, size, id;
-       char idstr[37];
+       char idstr[UUID_STR_LEN];
 
 
        data = blkid_probe_get_sector(pr, 0);
index 626e11729f22903f77657f93ef2d6beb869a0e28..d8fc8e3c8e402cafc6a5c6d7535550a1aa94a645 100644 (file)
@@ -166,7 +166,7 @@ struct blkid_struct_parttable {
        uint64_t        offset;         /* begin of the partition table (in bytes) */
        int             nparts;         /* number of partitions */
        blkid_partition parent;         /* parent of nested partition table */
-       char            id[37];         /* PT identifier (e.g. UUID for GPT) */
+       char            id[UUID_STR_LEN]; /* PT identifier (e.g. UUID for GPT) */
 
        struct list_head t_tabs;        /* all tables */
 };
@@ -177,12 +177,12 @@ struct blkid_struct_partition {
        uint64_t        size;           /* size of the partitions (512-bytes sectors) */
 
        int             type;           /* partition type */
-       char            typestr[37];    /* partition type string (GPT and Mac) */
+       char            typestr[UUID_STR_LEN]; /* partition type string (GPT and Mac) */
 
        unsigned long long flags;       /* partition flags / attributes */
 
        int             partno;         /* partition number */
-       char            uuid[37];       /* UUID (when supported by PT), e.g GPT */
+       char            uuid[UUID_STR_LEN]; /* UUID (when supported by PT), e.g GPT */
        unsigned char   name[128];      /* Partition in UTF8 name (when supported by PT), e.g. Mac */
 
        blkid_parttable tab;            /* partition table */
@@ -1122,7 +1122,7 @@ int blkid_partitions_set_ptuuid(blkid_probe pr, unsigned char *uuid)
        if (!v)
                return -ENOMEM;
 
-       v->len = 37;
+       v->len = UUID_STR_LEN;
        v->data = calloc(1, v->len);
        if (v->data) {
                blkid_unparse_uuid(uuid, (char *) v->data, v->len);
index 1d99fb6a36e56f0444ec4d6df9bac9ad9e9d263f..5ed2681e307a5d0dc64b51832aefa33cced42a6e 100644 (file)
@@ -4,6 +4,10 @@
 #include "blkidP.h"
 #include "pt-mbr.h"
 
+#ifndef UUID_STR_LEN
+#define UUID_STR_LEN   37
+#endif
+
 extern int blkid_partitions_get_flags(blkid_probe pr);
 
 extern blkid_parttable blkid_partlist_new_parttable(blkid_partlist ls,
index e631e90ac822b85757fe02774046586383e814aa..6b025ee1fc398d5956888984e93dc00980e0b55b 100644 (file)
@@ -768,7 +768,7 @@ int blkid_probe_set_uuid_as(blkid_probe pr, unsigned char *uuid, const char *nam
        if (!v)
                return -ENOMEM;
 
-       v->len = 37;
+       v->len = UUID_STR_LEN;
        v->data = calloc(1, v->len);
        if (!v->data)
                rc = -ENOMEM;
index 695c3b783d59b7a8fa5f2fdecbaebc12928a586a..3dea7b88139798daa89351d6523bdb9fbb5b84e8 100644 (file)
@@ -9,6 +9,10 @@
 
 #include "blkidP.h"
 
+#ifndef UUID_STR_LEN
+#define UUID_STR_LEN   37
+#endif
+
 extern const struct blkid_idinfo cramfs_idinfo;
 extern const struct blkid_idinfo swap_idinfo;
 extern const struct blkid_idinfo swsuspend_idinfo;
index 3a9d51da1efc26dece1e04a4c53ec59f4d4059e3..7134a36ce295b844fb421ce36f3f3923273aeca5 100644 (file)
@@ -286,6 +286,10 @@ static struct fdisk_parttype gpt_parttypes[] =
 #define gpt_partition_start(_e)                le64_to_cpu((_e)->lba_start)
 #define gpt_partition_end(_e)          le64_to_cpu((_e)->lba_end)
 
+#ifndef UUID_STR_LEN
+#define UUID_STR_LEN   37
+#endif
+
 /*
  * in-memory fdisk GPT stuff
  */
@@ -368,7 +372,7 @@ static struct fdisk_parttype *gpt_partition_parttype(
                const struct gpt_entry *e)
 {
        struct fdisk_parttype *t;
-       char str[37];
+       char str[UUID_STR_LEN];
        struct gpt_guid guid = e->type;
 
        guid_to_string(&guid, str);
@@ -482,7 +486,7 @@ static inline int gpt_sizeof_ents(struct gpt_header *hdr, size_t *sz)
 
 static char *gpt_get_header_id(struct gpt_header *header)
 {
-       char str[37];
+       char str[UUID_STR_LEN];
        struct gpt_guid guid = header->disk_guid;
 
        guid_to_string(&guid, str);
@@ -1735,7 +1739,7 @@ static int gpt_get_partition(struct fdisk_context *cxt, size_t n,
 {
        struct fdisk_gpt_label *gpt;
        struct gpt_entry *e;
-       char u_str[37];
+       char u_str[UUID_STR_LEN];
        int rc = 0;
        struct gpt_guid guid;
 
@@ -1805,7 +1809,7 @@ static int gpt_set_partition(struct fdisk_context *cxt, size_t n,
        e = gpt_get_entry(gpt, n);
 
        if (pa->uuid) {
-               char new_u[37], old_u[37];
+               char new_u[UUID_STR_LEN], old_u[UUID_STR_LEN];
                struct gpt_guid guid;
 
                guid = e->partition_guid;
@@ -2473,7 +2477,7 @@ static int gpt_create_disklabel(struct fdisk_context *cxt)
 {
        int rc = 0;
        size_t esz = 0;
-       char str[37];
+       char str[UUID_STR_LEN];
        struct fdisk_gpt_label *gpt;
        struct gpt_guid guid;
 
index 4d155b5338569846d62eb64162f6acafdd6519cf..400d6d8fc1dfa7ca62be59a7926020e9546737b0 100644 (file)
@@ -68,7 +68,7 @@ static int check_uuids_in_file(const char *file)
 {
        int fd, ret = 0;
        size_t sz;
-       char str[sizeof("01234567-89ab-cdef-0134-567890abcedf")];
+       char str[UUID_STR_LEN];
        uuid_t uuidBits;
 
        if ((fd = open(file, O_RDONLY)) < 0) {
index bf4e500630f2ec21a5291a45528ffc4accbd6a44..2fd470558e05b84d1c2c5dae6bd152b85b371539 100644 (file)
@@ -99,6 +99,8 @@ extern int uuid_is_null(const uuid_t uu);
 /* parse.c */
 extern int uuid_parse(const char *in, uuid_t uu);
 
+#define UUID_STR_LEN   37
+
 /* unparse.c */
 extern void uuid_unparse(const uuid_t uu, char *out);
 extern void uuid_unparse_lower(const uuid_t uu, char *out);
index de5ae3ab2060dcb4a6e19d7c82ea8f32caae4215..3f38fa4306c861433eaa0ac7fd6e39dcd8d13d72 100644 (file)
@@ -247,7 +247,7 @@ static void create_nprocesses(void)
 
 static void object_dump(size_t idx, object_t *obj)
 {
-       char uuid_string[37], *p;
+       char uuid_string[UUID_STR_LEN], *p;
 
        p = uuid_string;
        object_uuid_to_string(obj, &p);
index 2cfb383f0899726e67190ea8e2f6b1f37339f0e3..e7c25cfa1f932ee7b08a6728e8882ca26b0d422b 100644 (file)
@@ -41,9 +41,6 @@
 
 #include "nls.h"
 
-/* length of textual representation of UUID, including trailing \0 */
-#define UUID_STR_LEN   37
-
 /* length of binary representation of UUID */
 #define UUID_LEN       (sizeof(uuid_t))
 
index e33e43bf0f0ef96c74374e90f264b229a37b93a8..ac950747d7de6345cd802da8f1fcc0acdada156e 100644 (file)
@@ -42,7 +42,7 @@ main (int argc, char *argv[])
 {
        int    c;
        int    do_type = 0;
-       char   str[37];
+       char   str[UUID_STR_LEN];
        uuid_t uu;
 
        static const struct option longopts[] = {
index 641facb1fdc151d57610c1170bf76fb0008c9da1..1e7d3c0b527a308e2661c9bc5ffbfdfc323e13d7 100644 (file)
 
 #define MAX_PAGESIZE   (64 * 1024)
 
+#ifndef UUID_STR_LEN
+#define UUID_STR_LEN   37
+#endif
+
 enum {
        SIG_SWAPSPACE = 1,
        SIG_SWSUSPEND
@@ -485,7 +489,7 @@ static void swap_get_info(struct swap_device *dev, const char *hdr)
 
        if (s && *s->uuid) {
                const unsigned char *u = s->uuid;
-               char str[37];
+               char str[UUID_STR_LEN];
 
                snprintf(str, sizeof(str),
                        "%02x%02x%02x%02x-"
index 1bbf8754d14a61ee14cc9cd464ebe895a5cfc760..1522ed2bc909be0d6ef2eb0e629334425719a675 100644 (file)
@@ -7,7 +7,7 @@
 static void get_template(const char *ns)
 {
        const uuid_t *uuidptr;
-       char buf[37];
+       char buf[UUID_STR_LEN];
 
        uuidptr = uuid_get_template(ns);
        if (uuidptr == NULL)