simple KNF bin/{cp,dd,ed,mt}

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

simple KNF bin/{cp,dd,ed,mt}

Jasper Lievisse Adriaanse
sizeof foobar -> sizeof(foobar) and sizeof (foobar) -> sizeof(foobar)

--------------------8<--------------------
Index: cp.c
===================================================================
RCS file: /cvs/src/bin/cp/cp.c,v
retrieving revision 1.30
diff -u -r1.30 cp.c
--- cp.c 9 Nov 2005 20:03:29 -0000 1.30
+++ cp.c 24 Mar 2006 10:49:32 -0000
@@ -177,7 +177,7 @@

  /* Save the target base in "to". */
  target = argv[--argc];
- if (strlcpy(to.p_path, target, sizeof to.p_path) >= sizeof(to.p_path))
+ if (strlcpy(to.p_path, target, sizeof(to.p_path)) >= sizeof(to.p_path))
  errx(1, "%s: name too long", target);
  to.p_end = to.p_path + strlen(to.p_path);
  if (to.p_path == to.p_end) {

--------------------8<--------------------
? dd.cat1
Index: args.c
===================================================================
RCS file: /cvs/src/bin/dd/args.c,v
retrieving revision 1.15
diff -u -r1.15 args.c
--- args.c 8 Apr 2005 01:46:45 -0000 1.15
+++ args.c 24 Mar 2006 11:20:13 -0000
@@ -322,7 +322,7 @@
  * 2) A positive decimal number followed by a b (mult by 512).
  * 3) A positive decimal number followed by a k (mult by 1024).
  * 4) A positive decimal number followed by a m (mult by 1048576).
- * 5) A positive decimal number followed by a w (mult by sizeof int)
+ * 5) A positive decimal number followed by a w (mult by sizeof(int) ).
  * 6) Two or more positive decimal numbers (with/without k,b or w).
  *   separated by x (also * for backwards compatibility), specifying
  *   the product of the indicated values.
@@ -392,7 +392,7 @@
  * 2) A positive decimal number followed by a b (mult by 512).
  * 3) A positive decimal number followed by a k (mult by 1024).
  * 4) A positive decimal number followed by a m (mult by 1048576).
- * 5) A positive decimal number followed by a w (mult by sizeof int)
+ * 5) A positive decimal number followed by a w (mult by sizeof(int) ).
  * 6) Two or more positive decimal numbers (with/without k,b or w).
  *   separated by x (also * for backwards compatibility), specifying
  *   the product of the indicated values.

--------------------8<--------------------
? ed.cat1
Index: buf.c
===================================================================
RCS file: /cvs/src/bin/ed/buf.c,v
retrieving revision 1.16
diff -u -r1.16 buf.c
--- buf.c 18 Oct 2003 19:15:43 -0000 1.16
+++ buf.c 24 Mar 2006 11:24:11 -0000
@@ -208,7 +208,7 @@
  int fd = -1;

  isbinary = newline_added = 0;
- strlcpy(sfn, SCRATCH_TEMPLATE, sizeof sfn);
+ strlcpy(sfn, SCRATCH_TEMPLATE, sizeof(sfn));
  if ((fd = mkstemp(sfn)) == -1 ||
     (sfp = fdopen(fd, "w+")) == NULL) {
  if (fd != -1)
Index: cbc.c
===================================================================
RCS file: /cvs/src/bin/ed/cbc.c,v
retrieving revision 1.13
diff -u -r1.13 cbc.c
--- cbc.c 8 May 2004 07:05:19 -0000 1.13
+++ cbc.c 24 Mar 2006 11:24:11 -0000
@@ -139,7 +139,7 @@
 put_des_char(int c, FILE *fp)
 {
 #ifdef DES
- if (des_n == sizeof des_buf) {
+ if (des_n == sizeof(des_buf)) {
  des_ct = cbc_encode((char *)des_buf, des_n, fp);
  des_n = 0;
  }
@@ -153,7 +153,7 @@
 flush_des_file(FILE *fp)
 {
 #ifdef DES
- if (des_n == sizeof des_buf) {
+ if (des_n == sizeof(des_buf)) {
  des_ct = cbc_encode((char *)des_buf, des_n, fp);
  des_n = 0;
  }
@@ -182,7 +182,7 @@
  expand_des_key(BUFFER(msgbuf), p);
  MEMZERO(p, _PASSWORD_LEN);
  set_des_key(msgbuf);
- MEMZERO(msgbuf, sizeof msgbuf);
+ MEMZERO(msgbuf, sizeof(msgbuf));
  return 1;
  }
  return 0;
Index: main.c
===================================================================
RCS file: /cvs/src/bin/ed/main.c,v
retrieving revision 1.28
diff -u -r1.28 main.c
--- main.c 11 Jun 2003 23:42:12 -0000 1.28
+++ main.c 24 Mar 2006 11:24:11 -0000
@@ -195,7 +195,7 @@
  quit(2);
  else if (**argv != '!')
  strlcpy(old_filename, *argv,
-    sizeof old_filename);
+    sizeof(old_filename));
  } else if (argc) {
  fputs("?\n", stderr);
  if (**argv == '\0')
@@ -550,7 +550,7 @@
  else if (open_sbuf() < 0)
  return FATAL;
  if (*fnp && *fnp != '!')
- strlcpy(old_filename, fnp, sizeof old_filename);
+ strlcpy(old_filename, fnp, sizeof(old_filename));
 #ifdef BACKWARDS
  if (*fnp == '\0' && *old_filename == '\0') {
  seterrmsg("no current filename");
@@ -578,7 +578,7 @@
  }
  GET_COMMAND_SUFFIX();
  if (*fnp)
- strlcpy(old_filename, fnp, sizeof old_filename);
+ strlcpy(old_filename, fnp, sizeof(old_filename));
  puts(strip_escapes(old_filename));
  break;
  case 'g':
@@ -709,7 +709,7 @@
  GET_COMMAND_SUFFIX();
  if (!isglobal) clear_undo_stack();
  if (*old_filename == '\0' && *fnp != '!')
- strlcpy(old_filename, fnp, sizeof old_filename);
+ strlcpy(old_filename, fnp, sizeof(old_filename));
 #ifdef BACKWARDS
  if (*fnp == '\0' && *old_filename == '\0') {
  seterrmsg("no current filename");
@@ -849,7 +849,7 @@
  return ERR;
  GET_COMMAND_SUFFIX();
  if (*old_filename == '\0' && *fnp != '!')
- strlcpy(old_filename, fnp, sizeof old_filename);
+ strlcpy(old_filename, fnp, sizeof(old_filename));
 #ifdef BACKWARDS
  if (*fnp == '\0' && *old_filename == '\0') {
  seterrmsg("no current filename");
Index: re.c
===================================================================
RCS file: /cvs/src/bin/ed/re.c,v
retrieving revision 1.10
diff -u -r1.10 re.c
--- re.c 11 Jun 2003 23:42:12 -0000 1.10
+++ re.c 24 Mar 2006 11:24:11 -0000
@@ -74,7 +74,7 @@
  }
  patlock = 0;
  if ((n = regcomp(exp, exps, 0)) != 0) {
- regerror(n, exp, errmsg, sizeof errmsg);
+ regerror(n, exp, errmsg, sizeof(errmsg));
  free(exp);
  return exp = NULL;
  }

--------------------8<--------------------
Index: mtrmt.c
===================================================================
RCS file: /cvs/src/bin/mt/mtrmt.c,v
retrieving revision 1.16
diff -u -r1.16 mtrmt.c
--- mtrmt.c 23 Mar 2006 23:03:07 -0000 1.16
+++ mtrmt.c 24 Mar 2006 11:36:49 -0000
@@ -155,16 +155,16 @@
  size += 2 * 1024;

  while (size > TP_BSIZE &&
-    setsockopt(rmtape, SOL_SOCKET, SO_SNDBUF, &size, sizeof (size)) < 0)
+    setsockopt(rmtape, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size)) < 0)
     size -= TP_BSIZE;
- (void)setsockopt(rmtape, SOL_SOCKET, SO_RCVBUF, &size, sizeof (size));
+ (void)setsockopt(rmtape, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));

  maxseg = 1024;
  (void)setsockopt(rmtape, IPPROTO_TCP, TCP_MAXSEG, &maxseg,
- sizeof (maxseg));
+ sizeof(maxseg));

 #ifdef notdef
- if (setsockopt(rmtape, IPPROTO_TCP, TCP_NODELAY, &on, sizeof (on)) < 0)
+ if (setsockopt(rmtape, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)) < 0)
  perror("TCP_NODELAY setsockopt");
 #endif
 }
@@ -190,7 +190,7 @@
 {
  char buf[256];

- (void)snprintf(buf, sizeof (buf), "O%s\n%d\n", tape, mode);
+ (void)snprintf(buf, sizeof(buf), "O%s\n%d\n", tape, mode);
  rmtstate = TS_OPEN;
  return (rmtcall(tape, buf));
 }
@@ -228,7 +228,7 @@

  if (count < 0)
  return (-1);
- (void)snprintf(buf, sizeof (buf), "I%d\n%d\n", cmd, count);
+ (void)snprintf(buf, sizeof(buf), "I%d\n%d\n", cmd, count);
  return (rmtcall("ioctl", buf));
 }

@@ -247,9 +247,9 @@
  char *cp;
  char code[30], emsg[BUFSIZ];

- rmtgets(code, sizeof (code));
+ rmtgets(code, sizeof(code));
  if (*code == 'E' || *code == 'F') {
- rmtgets(emsg, sizeof (emsg));
+ rmtgets(emsg, sizeof(emsg));
  warnx("%s: %s", cmd, emsg);
  if (*code == 'F') {
  rmtstate = TS_CLOSED;

--------------------8<--------------------

--
Humppa is a serious thing!

[demime 1.01d removed an attachment of type application/pgp-signature]

Reply | Threaded
Open this post in threaded view
|

Re: simple KNF bin/{cp,dd,ed,mt}

Ray Lai
On Fri, Mar 24, 2006 at 01:58:35PM +0100, Jasper Lievisse Adriaanse wrote:
> sizeof foobar -> sizeof(foobar) and sizeof (foobar) -> sizeof(foobar)

Sorry, no more of these diffs.  Please spend your time on fixing
bugs instead of applying style(9).

-Ray-

> --------------------8<--------------------
> Index: cp.c
> ===================================================================
> RCS file: /cvs/src/bin/cp/cp.c,v
> retrieving revision 1.30
> diff -u -r1.30 cp.c
> --- cp.c 9 Nov 2005 20:03:29 -0000 1.30
> +++ cp.c 24 Mar 2006 10:49:32 -0000
> @@ -177,7 +177,7 @@
>
>   /* Save the target base in "to". */
>   target = argv[--argc];
> - if (strlcpy(to.p_path, target, sizeof to.p_path) >= sizeof(to.p_path))
> + if (strlcpy(to.p_path, target, sizeof(to.p_path)) >= sizeof(to.p_path))
>   errx(1, "%s: name too long", target);
>   to.p_end = to.p_path + strlen(to.p_path);
>   if (to.p_path == to.p_end) {
>
> --------------------8<--------------------
> ? dd.cat1
> Index: args.c
> ===================================================================
> RCS file: /cvs/src/bin/dd/args.c,v
> retrieving revision 1.15
> diff -u -r1.15 args.c
> --- args.c 8 Apr 2005 01:46:45 -0000 1.15
> +++ args.c 24 Mar 2006 11:20:13 -0000
> @@ -322,7 +322,7 @@
>   * 2) A positive decimal number followed by a b (mult by 512).
>   * 3) A positive decimal number followed by a k (mult by 1024).
>   * 4) A positive decimal number followed by a m (mult by 1048576).
> - * 5) A positive decimal number followed by a w (mult by sizeof int)
> + * 5) A positive decimal number followed by a w (mult by sizeof(int) ).
>   * 6) Two or more positive decimal numbers (with/without k,b or w).
>   *   separated by x (also * for backwards compatibility), specifying
>   *   the product of the indicated values.
> @@ -392,7 +392,7 @@
>   * 2) A positive decimal number followed by a b (mult by 512).
>   * 3) A positive decimal number followed by a k (mult by 1024).
>   * 4) A positive decimal number followed by a m (mult by 1048576).
> - * 5) A positive decimal number followed by a w (mult by sizeof int)
> + * 5) A positive decimal number followed by a w (mult by sizeof(int) ).
>   * 6) Two or more positive decimal numbers (with/without k,b or w).
>   *   separated by x (also * for backwards compatibility), specifying
>   *   the product of the indicated values.
>
> --------------------8<--------------------
> ? ed.cat1
> Index: buf.c
> ===================================================================
> RCS file: /cvs/src/bin/ed/buf.c,v
> retrieving revision 1.16
> diff -u -r1.16 buf.c
> --- buf.c 18 Oct 2003 19:15:43 -0000 1.16
> +++ buf.c 24 Mar 2006 11:24:11 -0000
> @@ -208,7 +208,7 @@
>   int fd = -1;
>
>   isbinary = newline_added = 0;
> - strlcpy(sfn, SCRATCH_TEMPLATE, sizeof sfn);
> + strlcpy(sfn, SCRATCH_TEMPLATE, sizeof(sfn));
>   if ((fd = mkstemp(sfn)) == -1 ||
>      (sfp = fdopen(fd, "w+")) == NULL) {
>   if (fd != -1)
> Index: cbc.c
> ===================================================================
> RCS file: /cvs/src/bin/ed/cbc.c,v
> retrieving revision 1.13
> diff -u -r1.13 cbc.c
> --- cbc.c 8 May 2004 07:05:19 -0000 1.13
> +++ cbc.c 24 Mar 2006 11:24:11 -0000
> @@ -139,7 +139,7 @@
>  put_des_char(int c, FILE *fp)
>  {
>  #ifdef DES
> - if (des_n == sizeof des_buf) {
> + if (des_n == sizeof(des_buf)) {
>   des_ct = cbc_encode((char *)des_buf, des_n, fp);
>   des_n = 0;
>   }
> @@ -153,7 +153,7 @@
>  flush_des_file(FILE *fp)
>  {
>  #ifdef DES
> - if (des_n == sizeof des_buf) {
> + if (des_n == sizeof(des_buf)) {
>   des_ct = cbc_encode((char *)des_buf, des_n, fp);
>   des_n = 0;
>   }
> @@ -182,7 +182,7 @@
>   expand_des_key(BUFFER(msgbuf), p);
>   MEMZERO(p, _PASSWORD_LEN);
>   set_des_key(msgbuf);
> - MEMZERO(msgbuf, sizeof msgbuf);
> + MEMZERO(msgbuf, sizeof(msgbuf));
>   return 1;
>   }
>   return 0;
> Index: main.c
> ===================================================================
> RCS file: /cvs/src/bin/ed/main.c,v
> retrieving revision 1.28
> diff -u -r1.28 main.c
> --- main.c 11 Jun 2003 23:42:12 -0000 1.28
> +++ main.c 24 Mar 2006 11:24:11 -0000
> @@ -195,7 +195,7 @@
>   quit(2);
>   else if (**argv != '!')
>   strlcpy(old_filename, *argv,
> -    sizeof old_filename);
> +    sizeof(old_filename));
>   } else if (argc) {
>   fputs("?\n", stderr);
>   if (**argv == '\0')
> @@ -550,7 +550,7 @@
>   else if (open_sbuf() < 0)
>   return FATAL;
>   if (*fnp && *fnp != '!')
> - strlcpy(old_filename, fnp, sizeof old_filename);
> + strlcpy(old_filename, fnp, sizeof(old_filename));
>  #ifdef BACKWARDS
>   if (*fnp == '\0' && *old_filename == '\0') {
>   seterrmsg("no current filename");
> @@ -578,7 +578,7 @@
>   }
>   GET_COMMAND_SUFFIX();
>   if (*fnp)
> - strlcpy(old_filename, fnp, sizeof old_filename);
> + strlcpy(old_filename, fnp, sizeof(old_filename));
>   puts(strip_escapes(old_filename));
>   break;
>   case 'g':
> @@ -709,7 +709,7 @@
>   GET_COMMAND_SUFFIX();
>   if (!isglobal) clear_undo_stack();
>   if (*old_filename == '\0' && *fnp != '!')
> - strlcpy(old_filename, fnp, sizeof old_filename);
> + strlcpy(old_filename, fnp, sizeof(old_filename));
>  #ifdef BACKWARDS
>   if (*fnp == '\0' && *old_filename == '\0') {
>   seterrmsg("no current filename");
> @@ -849,7 +849,7 @@
>   return ERR;
>   GET_COMMAND_SUFFIX();
>   if (*old_filename == '\0' && *fnp != '!')
> - strlcpy(old_filename, fnp, sizeof old_filename);
> + strlcpy(old_filename, fnp, sizeof(old_filename));
>  #ifdef BACKWARDS
>   if (*fnp == '\0' && *old_filename == '\0') {
>   seterrmsg("no current filename");
> Index: re.c
> ===================================================================
> RCS file: /cvs/src/bin/ed/re.c,v
> retrieving revision 1.10
> diff -u -r1.10 re.c
> --- re.c 11 Jun 2003 23:42:12 -0000 1.10
> +++ re.c 24 Mar 2006 11:24:11 -0000
> @@ -74,7 +74,7 @@
>   }
>   patlock = 0;
>   if ((n = regcomp(exp, exps, 0)) != 0) {
> - regerror(n, exp, errmsg, sizeof errmsg);
> + regerror(n, exp, errmsg, sizeof(errmsg));
>   free(exp);
>   return exp = NULL;
>   }
>
> --------------------8<--------------------
> Index: mtrmt.c
> ===================================================================
> RCS file: /cvs/src/bin/mt/mtrmt.c,v
> retrieving revision 1.16
> diff -u -r1.16 mtrmt.c
> --- mtrmt.c 23 Mar 2006 23:03:07 -0000 1.16
> +++ mtrmt.c 24 Mar 2006 11:36:49 -0000
> @@ -155,16 +155,16 @@
>   size += 2 * 1024;
>
>   while (size > TP_BSIZE &&
> -    setsockopt(rmtape, SOL_SOCKET, SO_SNDBUF, &size, sizeof (size)) < 0)
> +    setsockopt(rmtape, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size)) < 0)
>      size -= TP_BSIZE;
> - (void)setsockopt(rmtape, SOL_SOCKET, SO_RCVBUF, &size, sizeof (size));
> + (void)setsockopt(rmtape, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));
>
>   maxseg = 1024;
>   (void)setsockopt(rmtape, IPPROTO_TCP, TCP_MAXSEG, &maxseg,
> - sizeof (maxseg));
> + sizeof(maxseg));
>
>  #ifdef notdef
> - if (setsockopt(rmtape, IPPROTO_TCP, TCP_NODELAY, &on, sizeof (on)) < 0)
> + if (setsockopt(rmtape, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)) < 0)
>   perror("TCP_NODELAY setsockopt");
>  #endif
>  }
> @@ -190,7 +190,7 @@
>  {
>   char buf[256];
>
> - (void)snprintf(buf, sizeof (buf), "O%s\n%d\n", tape, mode);
> + (void)snprintf(buf, sizeof(buf), "O%s\n%d\n", tape, mode);
>   rmtstate = TS_OPEN;
>   return (rmtcall(tape, buf));
>  }
> @@ -228,7 +228,7 @@
>
>   if (count < 0)
>   return (-1);
> - (void)snprintf(buf, sizeof (buf), "I%d\n%d\n", cmd, count);
> + (void)snprintf(buf, sizeof(buf), "I%d\n%d\n", cmd, count);
>   return (rmtcall("ioctl", buf));
>  }
>
> @@ -247,9 +247,9 @@
>   char *cp;
>   char code[30], emsg[BUFSIZ];
>
> - rmtgets(code, sizeof (code));
> + rmtgets(code, sizeof(code));
>   if (*code == 'E' || *code == 'F') {
> - rmtgets(emsg, sizeof (emsg));
> + rmtgets(emsg, sizeof(emsg));
>   warnx("%s: %s", cmd, emsg);
>   if (*code == 'F') {
>   rmtstate = TS_CLOSED;
>
> --------------------8<--------------------
>
> --
> Humppa is a serious thing!
>
> [demime 1.01d removed an attachment of type application/pgp-signature]