[PATCH] fix integer overflow in util/fcp.c, util/eraseall.c,
Hideki IWAMOTO
h-iwamoto at kit.hi-ho.ne.jp
Sat Mar 27 01:39:59 EST 2004
On Sat, 27 Mar 2004 02:05:29 +0900, Hideki IWAMOTO wrote...
> eraseall and fcp print wrong progress message for large partition (>=41944KB).
>
Sorry. Previous patch has problem in the handling small files.
This is corrected version.
? jffs2dump
Index: eraseall.c
===================================================================
RCS file: /home/cvs/mtd/util/eraseall.c,v
retrieving revision 1.12
diff -u -r1.12 eraseall.c
--- eraseall.c 2 May 2003 19:27:32 -0000 1.12
+++ eraseall.c 27 Mar 2004 06:28:40 -0000
@@ -93,7 +93,7 @@
printf
("\rErasing %d Kibyte @ %x -- %2d %% complete.",
meminfo.erasesize / 1024, erase.start,
- erase.start * 100 / meminfo.size);
+ (erase.start/meminfo.erasesize) * 100 / (meminfo.size/meminfo.erasesize));
}
fflush(stdout);
Index: fcp.c
===================================================================
RCS file: /home/cvs/mtd/util/fcp.c,v
retrieving revision 1.2
diff -u -r1.2 fcp.c
--- fcp.c 3 Apr 2003 11:43:37 -0000 1.2
+++ fcp.c 27 Mar 2004 06:28:40 -0000
@@ -59,7 +59,7 @@
#endif
#define KB(x) ((x) / 1024)
-#define PERCENTAGE(x,total) (((x) * 100) / (total))
+#define PERCENTAGE(x,total) ((x) <= 0xffffffff / 100 ? (x) * 100 / (total) : (x) / ((total) / 100))
/* size of read/write buffer */
#define BUFSIZE (10 * 1024)
----
Hideki IWAMOTO h-iwamoto at kit.hi-ho.ne.jp
More information about the linux-mtd
mailing list