Subject: bin/6031: egcs-reveales brace fixes for /usr/src/sbin
To: None <gnats-bugs@gnats.netbsd.org>
From: Erik Bertelsen <erik@q610.ebe.uni-c.dk>
List: netbsd-bugs
Date: 08/24/1998 23:17:11
>Number:         6031
>Category:       bin
>Synopsis:       egcs-reveales brace fixes for /usr/src/sbin
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Aug 24 14:20:03 1998
>Last-Modified:
>Originator:     Erik Bertelsen
>Organization:
	
>Release:        NetBSD-current 23 Aug 1998
>Environment:
	
System: NetBSD q610.ebe.uni-c.dk 1.3G NetBSD 1.3G (Q610) #184: Sun Aug 23 23:59:05 MEST 1998 erik@q610.ebe.uni-c.dk:/home/src/sys/arch/mac68k/compile/Q610 mac68k


>Description:
	egcs 1.1 produces new warnings suggesting to add more braces.
	This is my batch of patches for this warning related to
	/usr/src/sbin. It relates to several files:
Index: badsect/badsect.c
Index: ccdconfig/ccdconfig.c
Index: clri/clri.c
Index: dump/main.c
Index: dump/traverse.c
Index: fsck/fsck.c
Index: fsck_ffs/pass5.c
Index: fsck_msdos/check.c
Index: fsck_msdos/dir.c
Index: fsirand/fsirand.c
Index: mount/mount.c
Index: shutdown/shutdown.c
Index: tunefs/tunefs.c

	regards
	Erik Bertelsen
>How-To-Repeat:
>Fix:
Index: badsect/badsect.c
===================================================================
RCS file: /home/cvs-base/src/sbin/badsect/badsect.c,v
retrieving revision 1.1.1.4
diff -c -r1.1.1.4 badsect.c
*** badsect.c	1998/03/19 19:24:11	1.1.1.4
--- badsect.c	1998/08/24 15:09:31
***************
*** 148,158 ****
  
  	fs = &sblock;
  	rdfs(SBOFF, SBSIZE, (char *)fs);
! 	if (fs->fs_magic != FS_MAGIC)
  		if(fs->fs_magic == bswap32(FS_MAGIC))
  			needswap = 1;
  		else
  			errx(1, "%s: bad superblock", name);
  	if (needswap)
  		ffs_sb_swap(fs, fs, 0);
  	dev_bsize = fs->fs_fsize / fsbtodb(fs, 1);
--- 148,159 ----
  
  	fs = &sblock;
  	rdfs(SBOFF, SBSIZE, (char *)fs);
! 	if (fs->fs_magic != FS_MAGIC) {
  		if(fs->fs_magic == bswap32(FS_MAGIC))
  			needswap = 1;
  		else
  			errx(1, "%s: bad superblock", name);
+ 	}
  	if (needswap)
  		ffs_sb_swap(fs, fs, 0);
  	dev_bsize = fs->fs_fsize / fsbtodb(fs, 1);
Index: ccdconfig/ccdconfig.c
===================================================================
RCS file: /home/cvs-base/src/sbin/ccdconfig/ccdconfig.c,v
retrieving revision 1.1.1.13
diff -c -r1.1.1.13 ccdconfig.c
*** ccdconfig.c	1998/08/11 13:36:24	1.1.1.13
--- ccdconfig.c	1998/08/24 15:25:54
***************
*** 240,246 ****
  	}
  
  	/* Make sure there are enough arguments. */
! 	if (argc < 4)
  		if (argc == 3) {
  			/* Assume that no flags are specified. */
  			noflags = 1;
--- 240,246 ----
  	}
  
  	/* Make sure there are enough arguments. */
! 	if (argc < 4)  {
  		if (argc == 3) {
  			/* Assume that no flags are specified. */
  			noflags = 1;
***************
*** 252,257 ****
--- 252,258 ----
  			} else
  				usage();
  		}
+ 	}
  
  	/* First argument is the ccd to configure. */
  	cp = *argv++; --argc;
Index: clri/clri.c
===================================================================
RCS file: /home/cvs-base/src/sbin/clri/clri.c,v
retrieving revision 1.1.1.3
diff -c -r1.1.1.3 clri.c
*** clri.c	1998/03/19 19:24:15	1.1.1.3
--- clri.c	1998/08/24 19:45:47
***************
*** 102,113 ****
  		errx(1, "%s: can't read superblock", fs);
  
  	sbp = (struct fs *)sblock;
! 	if (sbp->fs_magic != FS_MAGIC)
  		if (sbp->fs_magic == bswap32(FS_MAGIC))
  			needswap = 1;
  		else
  			errx(1, "%s: superblock magic number 0x%x, not 0x%x",
  		    	fs, sbp->fs_magic, FS_MAGIC);
  
  	/* check that inode numbers are valid */
  	imax = ufs_rw32(sbp->fs_ncg, needswap) *
--- 102,114 ----
  		errx(1, "%s: can't read superblock", fs);
  
  	sbp = (struct fs *)sblock;
! 	if (sbp->fs_magic != FS_MAGIC) {
  		if (sbp->fs_magic == bswap32(FS_MAGIC))
  			needswap = 1;
  		else
  			errx(1, "%s: superblock magic number 0x%x, not 0x%x",
  		    	fs, sbp->fs_magic, FS_MAGIC);
+ 	}
  
  	/* check that inode numbers are valid */
  	imax = ufs_rw32(sbp->fs_ncg, needswap) *
Index: dump/main.c
===================================================================
RCS file: /home/cvs-base/src/sbin/dump/main.c,v
retrieving revision 1.1.1.11
diff -c -r1.1.1.11 main.c
*** main.c	1998/07/06 15:18:36	1.1.1.11
--- main.c	1998/08/24 18:44:55
***************
*** 362,373 ****
  	sync();
  	sblock = (struct fs *)sblock_buf;
  	bread(SBOFF, (char *) sblock, SBSIZE);
! 	if (sblock->fs_magic != FS_MAGIC)
  		if (sblock->fs_magic == bswap32(FS_MAGIC)) {
  			ffs_sb_swap(sblock, sblock, 0);
  			needswap = 1;
  		} else
  			quit("bad sblock magic number\n");
  
  	spcl.c_level = iswap32(level - '0');
  	spcl.c_type = iswap32(TS_TAPE);
--- 362,374 ----
  	sync();
  	sblock = (struct fs *)sblock_buf;
  	bread(SBOFF, (char *) sblock, SBSIZE);
! 	if (sblock->fs_magic != FS_MAGIC) {
  		if (sblock->fs_magic == bswap32(FS_MAGIC)) {
  			ffs_sb_swap(sblock, sblock, 0);
  			needswap = 1;
  		} else
  			quit("bad sblock magic number\n");
+ 	}
  
  	spcl.c_level = iswap32(level - '0');
  	spcl.c_type = iswap32(TS_TAPE);
Index: dump/traverse.c
===================================================================
RCS file: /home/cvs-base/src/sbin/dump/traverse.c,v
retrieving revision 1.1.1.5
diff -c -r1.1.1.5 traverse.c
*** traverse.c	1998/03/19 19:24:27	1.1.1.5
--- traverse.c	1998/08/24 18:45:29
***************
*** 566,576 ****
  		writeheader(ino);
  		bp = &blkp[i / tbperdb];
  		for (j = i; j < count; j += tbperdb, bp++)
! 			if (*bp != 0)
  				if (j + tbperdb <= count)
  					dumpblock(iswap32(*bp), (int)sblock->fs_bsize);
  				else
  					dumpblock(iswap32(*bp), (count - j) * TP_BSIZE);
  		spcl.c_type = iswap32(TS_ADDR);
  	}
  }
--- 566,577 ----
  		writeheader(ino);
  		bp = &blkp[i / tbperdb];
  		for (j = i; j < count; j += tbperdb, bp++)
! 			if (*bp != 0) {
  				if (j + tbperdb <= count)
  					dumpblock(iswap32(*bp), (int)sblock->fs_bsize);
  				else
  					dumpblock(iswap32(*bp), (count - j) * TP_BSIZE);
+ 			}
  		spcl.c_type = iswap32(TS_ADDR);
  	}
  }
Index: fsck/fsck.c
===================================================================
RCS file: /home/cvs-base/src/sbin/fsck/fsck.c,v
retrieving revision 1.1.1.8
diff -c -r1.1.1.8 fsck.c
*** fsck.c	1998/07/27 15:26:26	1.1.1.8
--- fsck.c	1998/08/24 17:18:41
***************
*** 274,291 ****
  			(void)snprintf(execname,
  			    sizeof(execname), "%s/%s", *edir, execbase);
  			execv(execname, (char * const *)argv);
! 			if (errno != ENOENT)
  				if (spec)
  					warn("exec %s for %s", execname, spec);
  				else
  					warn("exec %s", execname);
  		} while (*++edir != NULL);
  
! 		if (errno == ENOENT)
  			if (spec)
  				warn("exec %s for %s", execname, spec);
  			else
  				warn("exec %s", execname);
  		_exit(1);
  		/* NOTREACHED */
  
--- 274,293 ----
  			(void)snprintf(execname,
  			    sizeof(execname), "%s/%s", *edir, execbase);
  			execv(execname, (char * const *)argv);
! 			if (errno != ENOENT) {
  				if (spec)
  					warn("exec %s for %s", execname, spec);
  				else
  					warn("exec %s", execname);
+ 			}
  		} while (*++edir != NULL);
  
! 		if (errno == ENOENT) {
  			if (spec)
  				warn("exec %s for %s", execname, spec);
  			else
  				warn("exec %s", execname);
+ 		}
  		_exit(1);
  		/* NOTREACHED */
  
***************
*** 444,450 ****
  			maxargc <<= 1;
  			argv = erealloc(argv, maxargc * sizeof(char *));
  		}
! 		if (*p != '\0')
  			if (*p == '-') {
  				argv[argc++] = p;
  				p = strchr(p, '=');
--- 446,452 ----
  			maxargc <<= 1;
  			argv = erealloc(argv, maxargc * sizeof(char *));
  		}
! 		if (*p != '\0')  {
  			if (*p == '-') {
  				argv[argc++] = p;
  				p = strchr(p, '=');
***************
*** 456,461 ****
--- 458,464 ----
  				argv[argc++] = "-o";
  				argv[argc++] = p;
  			}
+ 		}
  	}
  
  	*argcp = argc;
Index: fsck_ffs/pass5.c
===================================================================
RCS file: /home/cvs-base/src/sbin/fsck_ffs/pass5.c,v
retrieving revision 1.1.1.3
diff -c -r1.1.1.3 pass5.c
*** pass5.c	1998/03/19 19:24:53	1.1.1.3
--- pass5.c	1998/08/24 19:45:22
***************
*** 312,323 ****
  		cstotal.cs_nifree += newcg->cg_cs.cs_nifree;
  		cstotal.cs_ndir += newcg->cg_cs.cs_ndir;
  		cs = &fs->fs_cs(fs, c);
! 		if (memcmp(&newcg->cg_cs, cs, sizeof *cs) != 0)
  			if (dofix(&idesc[0], "FREE BLK COUNT(S) WRONG IN SUPERBLK")) {
  			memmove(cs, &newcg->cg_cs, sizeof *cs);
  			sbdirty();
  			} else
  				markclean = 0;
  		if (doinglevel1) {
  			memmove(cg, newcg, (size_t)fs->fs_cgsize);
  			cgdirty();
--- 312,324 ----
  		cstotal.cs_nifree += newcg->cg_cs.cs_nifree;
  		cstotal.cs_ndir += newcg->cg_cs.cs_ndir;
  		cs = &fs->fs_cs(fs, c);
! 		if (memcmp(&newcg->cg_cs, cs, sizeof *cs) != 0) {
  			if (dofix(&idesc[0], "FREE BLK COUNT(S) WRONG IN SUPERBLK")) {
  			memmove(cs, &newcg->cg_cs, sizeof *cs);
  			sbdirty();
  			} else
  				markclean = 0;
+ 		}
  		if (doinglevel1) {
  			memmove(cg, newcg, (size_t)fs->fs_cgsize);
  			cgdirty();
***************
*** 339,356 ****
  		}
  		if (memcmp(newcg, cg, basesize) != 0 ||
  		     memcmp(&cg_blktot(newcg, 0)[0],
! 				&cg_blktot(cg, 0)[0], sumsize) != 0) 
  		    if (dofix(&idesc[2], "SUMMARY INFORMATION BAD")) {
  			memmove(cg, newcg, (size_t)basesize);
  			memmove(&cg_blktot(cg, 0)[0],
  			       &cg_blktot(newcg, 0)[0], (size_t)sumsize);
  			cgdirty();
  			} else markclean = 0;
  
  	}
  	if (fs->fs_postblformat == FS_42POSTBLFMT)
  		fs->fs_nrpos = savednrpos;
! 	if (memcmp(&cstotal, &fs->fs_cstotal, sizeof *cs) != 0)
  	    if(dofix(&idesc[0], "FREE BLK COUNT(S) WRONG IN SUPERBLK")) {
  		memmove(&fs->fs_cstotal, &cstotal, sizeof *cs);
  		fs->fs_ronly = 0;
--- 340,358 ----
  		}
  		if (memcmp(newcg, cg, basesize) != 0 ||
  		     memcmp(&cg_blktot(newcg, 0)[0],
! 				&cg_blktot(cg, 0)[0], sumsize) != 0) {
  		    if (dofix(&idesc[2], "SUMMARY INFORMATION BAD")) {
  			memmove(cg, newcg, (size_t)basesize);
  			memmove(&cg_blktot(cg, 0)[0],
  			       &cg_blktot(newcg, 0)[0], (size_t)sumsize);
  			cgdirty();
  			} else markclean = 0;
+ 		}
  
  	}
  	if (fs->fs_postblformat == FS_42POSTBLFMT)
  		fs->fs_nrpos = savednrpos;
! 	if (memcmp(&cstotal, &fs->fs_cstotal, sizeof *cs) != 0) {
  	    if(dofix(&idesc[0], "FREE BLK COUNT(S) WRONG IN SUPERBLK")) {
  		memmove(&fs->fs_cstotal, &cstotal, sizeof *cs);
  		fs->fs_ronly = 0;
***************
*** 358,363 ****
--- 360,366 ----
  		sbdirty();
  		} else
  			markclean = 0;
+ 	}
  }
  
  void 
Index: fsck_msdos/check.c
===================================================================
RCS file: /home/cvs-base/src/sbin/fsck_msdos/check.c,v
retrieving revision 1.1.1.4
diff -c -r1.1.1.4 check.c
*** check.c	1997/10/19 16:45:25	1.1.1.4
--- check.c	1998/08/24 18:57:53
***************
*** 83,93 ****
  		return 8;
  	}
  
! 	if (!preen)
  		if (boot.ValidFat < 0)
  			printf("** Phase 1 - Read and Compare FATs\n");
  		else
  			printf("** Phase 1 - Read FAT\n");
  
  	mod |= readfat(dosfs, &boot, boot.ValidFat >= 0 ? boot.ValidFat : 0, &fat);
  	if (mod & FSFATAL) {
--- 83,94 ----
  		return 8;
  	}
  
! 	if (!preen)  {
  		if (boot.ValidFat < 0)
  			printf("** Phase 1 - Read and Compare FATs\n");
  		else
  			printf("** Phase 1 - Read FAT\n");
+ 	}
  
  	mod |= readfat(dosfs, &boot, boot.ValidFat >= 0 ? boot.ValidFat : 0, &fat);
  	if (mod & FSFATAL) {
Index: fsck_msdos/dir.c
===================================================================
RCS file: /home/cvs-base/src/sbin/fsck_msdos/dir.c,v
retrieving revision 1.1.1.6
diff -c -r1.1.1.6 dir.c
*** dir.c	1998/07/29 16:22:35	1.1.1.6
--- dir.c	1998/08/24 18:58:49
***************
*** 803,809 ****
  					continue;
  				}
  				if (strcmp(dirent.name, "..") == 0) {
! 					if (dir->parent)		/* XXX */
  						if (!dir->parent->parent) {
  							if (dirent.head) {
  								pwarn("`..' entry in %s has non-zero start cluster\n",
--- 803,809 ----
  					continue;
  				}
  				if (strcmp(dirent.name, "..") == 0) {
! 					if (dir->parent) {		/* XXX */
  						if (!dir->parent->parent) {
  							if (dirent.head) {
  								pwarn("`..' entry in %s has non-zero start cluster\n",
***************
*** 832,837 ****
--- 832,838 ----
  							} else
  								mod |= FSERROR;
  						}
+ 					}
  					continue;
  				}
  
Index: fsirand/fsirand.c
===================================================================
RCS file: /home/cvs-base/src/sbin/fsirand/fsirand.c,v
retrieving revision 1.1.1.7
diff -c -r1.1.1.7 fsirand.c
*** fsirand.c	1998/03/19 19:25:10	1.1.1.7
--- fsirand.c	1998/08/24 17:28:50
***************
*** 105,116 ****
  	if (read(fd, fs, SBSIZE) != SBSIZE)
  		err(1, "Cannot read superblock");
  
! 	if (fs->fs_magic != FS_MAGIC)
  		if(fs->fs_magic == bswap32(FS_MAGIC)) {
  			needswap = 1;
  			ffs_sb_swap(fs, fs, 0);
  		} else
  			errx(1, "Bad superblock magic number");
  
  	if (fs->fs_ncg < 1)
  		errx(1, "Bad ncg in superblock");
--- 105,117 ----
  	if (read(fd, fs, SBSIZE) != SBSIZE)
  		err(1, "Cannot read superblock");
  
! 	if (fs->fs_magic != FS_MAGIC)  {
  		if(fs->fs_magic == bswap32(FS_MAGIC)) {
  			needswap = 1;
  			ffs_sb_swap(fs, fs, 0);
  		} else
  			errx(1, "Bad superblock magic number");
+ 	}
  
  	if (fs->fs_ncg < 1)
  		errx(1, "Bad ncg in superblock");
Index: mount/mount.c
===================================================================
RCS file: /home/cvs-base/src/sbin/mount/mount.c,v
retrieving revision 1.1.1.11
diff -c -r1.1.1.11 mount.c
*** mount.c	1998/07/27 15:26:47	1.1.1.11
--- mount.c	1998/08/24 19:42:59
***************
*** 535,541 ****
  			maxargc <<= 1;
  			argv = realloc(argv, maxargc * sizeof(char *));
  		}
! 		if (*p != '\0')
  			if (*p == '-') {
  				argv[argc++] = p;
  				p = strchr(p, '=');
--- 535,541 ----
  			maxargc <<= 1;
  			argv = realloc(argv, maxargc * sizeof(char *));
  		}
! 		if (*p != '\0') {
  			if (*p == '-') {
  				argv[argc++] = p;
  				p = strchr(p, '=');
***************
*** 547,552 ****
--- 547,553 ----
  				argv[argc++] = "-o";
  				argv[argc++] = p;
  			}
+ 		}
  	}
  
  	*argcp = argc;
Index: shutdown/shutdown.c
===================================================================
RCS file: /home/cvs-base/src/sbin/shutdown/shutdown.c,v
retrieving revision 1.1.1.11
diff -c -r1.1.1.11 shutdown.c
*** shutdown.c	1998/07/27 15:26:59	1.1.1.11
--- shutdown.c	1998/08/24 19:43:47
***************
*** 173,179 ****
  
  	getoffset(*argv++);
  
! 	if (argv[0])
  		if (strcmp(argv[0], "-") || argv[1]) {
  			for (p = mbuf, len = sizeof(mbuf); *argv; ++argv) {
  				arglen = strlen(*argv);
--- 173,179 ----
  
  	getoffset(*argv++);
  
! 	if (argv[0]) {
  		if (strcmp(argv[0], "-") || argv[1]) {
  			for (p = mbuf, len = sizeof(mbuf); *argv; ++argv) {
  				arglen = strlen(*argv);
***************
*** 200,205 ****
--- 200,206 ----
  				}
  			}
  		}
+ 	}
  	mbuflen = strlen(mbuf);
  
  	if (offset)
***************
*** 420,426 ****
  
  	/* handle hh:mm by getting rid of the colon */
  	for (p = timearg; *p; ++p)
! 		if (!isascii(*p) || !isdigit(*p))
  			if (*p == ':' && strlen(p) == 3) {
  				p[0] = p[1];
  				p[1] = p[2];
--- 421,427 ----
  
  	/* handle hh:mm by getting rid of the colon */
  	for (p = timearg; *p; ++p)
! 		if (!isascii(*p) || !isdigit(*p)) {
  			if (*p == ':' && strlen(p) == 3) {
  				p[0] = p[1];
  				p[1] = p[2];
***************
*** 428,433 ****
--- 429,435 ----
  			}
  			else
  				badtime();
+ 		}
  
  	unsetenv("TZ");					/* OUR timezone */
  	lt = localtime(&now);				/* current time val */
Index: tunefs/tunefs.c
===================================================================
RCS file: /home/cvs-base/src/sbin/tunefs/tunefs.c,v
retrieving revision 1.1.1.6
diff -c -r1.1.1.6 tunefs.c
*** tunefs.c	1998/07/29 16:22:53	1.1.1.6
--- tunefs.c	1998/08/24 19:46:12
***************
*** 304,315 ****
  		err(3, "cannot open %s for reading", file);
  	if (bread((daddr_t)SBOFF, (char *)fs, SBSIZE))
  		err(4, "%s: bad super block", file);
! 	if (fs->fs_magic != FS_MAGIC)
  		if (fs->fs_magic == bswap32(FS_MAGIC)) {
  			needswap = 1;
  			ffs_sb_swap(fs, fs, 0);
  		} else
  			err(5, "%s: bad magic number", file);
  	dev_bsize = fs->fs_fsize / fsbtodb(fs, 1);
  	close(fi);
  }
--- 304,316 ----
  		err(3, "cannot open %s for reading", file);
  	if (bread((daddr_t)SBOFF, (char *)fs, SBSIZE))
  		err(4, "%s: bad super block", file);
! 	if (fs->fs_magic != FS_MAGIC) {
  		if (fs->fs_magic == bswap32(FS_MAGIC)) {
  			needswap = 1;
  			ffs_sb_swap(fs, fs, 0);
  		} else
  			err(5, "%s: bad magic number", file);
+ 	}
  	dev_bsize = fs->fs_fsize / fsbtodb(fs, 1);
  	close(fi);
  }
>Audit-Trail:
>Unformatted: