]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Replace sprintf calls with snprintf
authorNeil Brown <neilb@suse.de>
Tue, 14 Jun 2005 06:42:13 +0000 (06:42 +0000)
committerNeil Brown <neilb@suse.de>
Tue, 14 Jun 2005 06:42:13 +0000 (06:42 +0000)
To quiet diet-libc

Signed-off-by: Neil Brown <neilb@cse.unsw.edu.au>
ChangeLog
bitmap.c
mdopen.c
super0.c
util.c

index 0e1c41a71c8ee7ea8f49c93d91e842aaf99cddec..f2f1c1183b6af5d9f72627026c6fd57ddcd5e97d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -20,6 +20,7 @@ Changes Prior to this release
        This is because the device list can change and so is not a
        stable aspect of the array
     -   Allow --force with --grow so '-Gfn1' works (on raid1)
+    -   Replace sprintf calls with snprintf (to quiet diet-libc)
        
 Changes Prior to 1.11.0 release
     -   Fix embarassing bug which causes --add to always fail.
index 83a70bccdc9fe39b69296c949351c83f85c7be59..c967af2f802bbd745513f9e5892ac77619d267b0 100644 (file)
--- a/bitmap.c
+++ b/bitmap.c
@@ -66,7 +66,7 @@ const char *human_chunksize(unsigned long bytes)
                i++;
        }
 
-       sprintf(buf, "%lu %s", bytes, suffixes[i]);
+       snprintf(buf, sizeof(buf), "%lu %s", bytes, suffixes[i]);
 
        return buf;
 }
index 9309fbd2f1a165224608883c624ecc667ad5e20f..81cf725b02c8c0f3e3b9de3e52c0d781e6ac3f43 100644 (file)
--- a/mdopen.c
+++ b/mdopen.c
@@ -42,7 +42,8 @@ void make_parts(char *dev, int cnt)
        struct stat stb;
        int major, minor;
        int i;
-       char *name = malloc(strlen(dev) + 20);
+       int nlen = strlen(dev) + 20;
+       char *name = malloc(nlen);
        int dig = isdigit(dev[strlen(dev)-1]);
 
        if (stat(dev, &stb)!= 0)
@@ -53,7 +54,7 @@ void make_parts(char *dev, int cnt)
        minor = minor(stb.st_rdev);
        for (i=1; i <= cnt ; i++) {
                struct stat stb2;
-               sprintf(name, "%s%s%d", dev, dig?"p":"", i);
+               snprintf(name, nlen, "%s%s%d", dev, dig?"p":"", i);
                if (stat(name, &stb2)==0) {
                        if (!S_ISBLK(stb2.st_mode))
                                continue;
index 0364da474cc2eb6cbc85de3f478fc2b870868a02..303ed889b60c326ee780135179e4ef1ce786918e 100644 (file)
--- a/super0.c
+++ b/super0.c
@@ -117,7 +117,7 @@ static void examine_super0(void *sbv)
                char nb[5];
                if (d>=0) dp = &sb->disks[d];
                else dp = &sb->this_disk;
-               sprintf(nb, "%4d", d);
+               snprintf(nb, sizeof(nb), "%4d", d);
                printf("%4s %5d   %5d    %5d    %5d     ", d < 0 ? "this" :  nb,
                       dp->number, dp->major, dp->minor, dp->raid_disk);
                if (dp->state & (1<<MD_DISK_FAULTY)) printf(" faulty");
diff --git a/util.c b/util.c
index 4445b1609ee901c79ad50ebb28fd185fa37221ea..fab01929caf0d8bf461543fba518668b16360e47 100644 (file)
--- a/util.c
+++ b/util.c
@@ -427,13 +427,13 @@ char *human_size(long long bytes)
        else if (bytes < 2*1024LL*1024LL*1024LL) {
                long cMiB = (bytes / ( (1LL<<20) / 200LL ) +1) /2;
                long cMB  = (bytes / ( 1000000LL / 200LL ) +1) /2;
-               sprintf(buf, " (%ld.%02ld MiB %ld.%02ld MB)",
+               snprintf(buf, sizeof(buf), " (%ld.%02ld MiB %ld.%02ld MB)",
                        cMiB/100 , cMiB % 100,
                        cMB/100, cMB % 100);
        } else {
                long cGiB = (bytes / ( (1LL<<30) / 200LL ) +1) /2;
                long cGB  = (bytes / (1000000000LL/200LL ) +1) /2;
-               sprintf(buf, " (%ld.%02ld GiB %ld.%02ld GB)",
+               snprintf(buf, sizeof(buf), " (%ld.%02ld GiB %ld.%02ld GB)",
                        cGiB/100 , cGiB % 100,
                        cGB/100, cGB % 100);
        }
@@ -446,16 +446,16 @@ char *human_size_brief(long long bytes)
        
 
        if (bytes < 5000*1024)
-               sprintf(buf, "%ld.%02ldKiB",
+               snprintf(buf, sizeof(buf), "%ld.%02ldKiB",
                        (long)(bytes>>10), (long)(((bytes&1023)*100+512)/1024)
                        );
        else if (bytes < 2*1024LL*1024LL*1024LL)
-               sprintf(buf, "%ld.%02ldMiB",
+               snprintf(buf, sizeof(buf), "%ld.%02ldMiB",
                        (long)(bytes>>20),
                        (long)((bytes&0xfffff)+0x100000/200)/(0x100000/100)
                        );
        else
-               sprintf(buf, "%ld.%02ldGiB",
+               snprintf(buf, sizeof(buf), "%ld.%02ldGiB",
                        (long)(bytes>>30),
                        (long)(((bytes>>10)&0xfffff)+0x100000/200)/(0x100000/100)
                        );
@@ -505,20 +505,20 @@ char *get_md_name(int dev)
                int mdp =  get_mdp_major();
                if (mdp < 0) return NULL;
                rdev = makedev(mdp, (-1-dev)<<6);
-               sprintf(devname, "/dev/md/d%d", -1-dev);
+               snprintf(devname, sizeof(devname), "/dev/md/d%d", -1-dev);
                if (stat(devname, &stb) == 0
                    && (S_IFMT&stb.st_mode) == S_IFBLK
                    && (stb.st_rdev == rdev))
                        return devname;
        } else {
                rdev = makedev(MD_MAJOR, dev);
-               sprintf(devname, "/dev/md%d", dev);
+               snprintf(devname, sizeof(devname), "/dev/md%d", dev);
                if (stat(devname, &stb) == 0
                    && (S_IFMT&stb.st_mode) == S_IFBLK
                    && (stb.st_rdev == rdev))
                        return devname;
 
-               sprintf(devname, "/dev/md/%d", dev);
+               snprintf(devname, sizeof(devname), "/dev/md/%d", dev);
                if (stat(devname, &stb) == 0
                    && (S_IFMT&stb.st_mode) == S_IFBLK
                    && (stb.st_rdev == rdev))
@@ -527,7 +527,7 @@ char *get_md_name(int dev)
        dn = map_dev(major(rdev), minor(rdev));
        if (dn)
                return dn;
-       sprintf(devname, "/dev/.tmp.md%d", dev);
+       snprintf(devname, sizeof(devname), "/dev/.tmp.md%d", dev);
        if (mknod(devname, S_IFBLK | 0600, rdev) == -1)
                if (errno != EEXIST)
                        return NULL;