summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Brown <neilb@suse.de>2005-06-14 06:42:13 +0000
committerNeil Brown <neilb@suse.de>2005-06-14 06:42:13 +0000
commit8f23b0b3fa61cb112a974a711fe3c424482fe11d (patch)
tree83e83d147cc5d1da0a6a9b3189a42b0d937f2b0b
parent173fc51539683030178a8f833281c787b1933ffd (diff)
downloadmdadm-8f23b0b3fa61cb112a974a711fe3c424482fe11d.tar.gz
mdadm-8f23b0b3fa61cb112a974a711fe3c424482fe11d.tar.xz
mdadm-8f23b0b3fa61cb112a974a711fe3c424482fe11d.zip
Replace sprintf calls with snprintf
To quiet diet-libc Signed-off-by: Neil Brown <neilb@cse.unsw.edu.au>
-rw-r--r--ChangeLog1
-rw-r--r--bitmap.c2
-rw-r--r--mdopen.c5
-rw-r--r--super0.c2
-rw-r--r--util.c18
5 files changed, 15 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 0e1c41a..f2f1c11 100644
--- 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.
diff --git a/bitmap.c b/bitmap.c
index 83a70bc..c967af2 100644
--- 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;
}
diff --git a/mdopen.c b/mdopen.c
index 9309fbd..81cf725 100644
--- 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;
diff --git a/super0.c b/super0.c
index 0364da4..303ed88 100644
--- 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 4445b16..fab0192 100644
--- 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;