Re: cvs commit: src/sbin/badsect Makefile badsect.c

看板DFBSD_commit作者時間21年前 (2005/02/18 21:35), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
On Sun, Feb 13, 2005 at 11:22:42AM -0800, Chris Pressey wrote: > cpressey 2005/02/13 11:22:42 PST > > DragonFly src repository > > Modified files: > sbin/badsect Makefile badsect.c > Log: > Raise WARNS to 6: > - Double-cast values when testing their ranges for validity. @@ -142,7 +142,7 @@ main(int argc, char **argv) * bit was lost by bogus sign extensions. */ diskbn = dbtofsb(fs, number); - if ((dev_t)diskbn != diskbn) { + if ((daddr_t)((dev_t)diskbn) != diskbn) { printf("sector %ld cannot be represented as a dev_t\n", (long)number); errs++; This is bad. The old code is evil, but that's even worse. Can you think of a better way to test it? @@ -163,7 +163,7 @@ chkuse(daddr_t blkno, int cnt) daddr_t fsbn, bn; fsbn = dbtofsb(fs, blkno); - if ((unsigned)(fsbn+cnt) > fs->fs_size) { + if ((int32_t)((unsigned)(fsbn+cnt)) > fs->fs_size) { printf("block %ld out of range of file system\n", (long)blkno); This part is bogus. fsbn + cnt can overflow and the int32_t cast makes it smaller than any non-negative fs->fs_size. Joerg
文章代碼(AID): #125Uy-00 (DFBSD_commit)
文章代碼(AID): #125Uy-00 (DFBSD_commit)