Re: [hackers][sbase][ed] small changes

From: Ali H. Fardan <raiz_AT_firemail.cc>
Date: Fri, 07 Oct 2016 16:26:37 +0300

Uhm, sorry about that, but my last patch violates the default ed
behavior
by using eprintf(), here is the corrected version:

diff --git a/ed.c b/ed.c
index 184ed30..1e834a6 100644
--- a/ed.c
+++ b/ed.c
_AT_@ -316,7 +316,7 @@ inject(char *s)
  }

  static void
-clearbuf()
+clearbuf(void)
  {
          if (scratch)
                  close(scratch);
_AT_@ -328,7 +328,7 @@ clearbuf()
  }

  static void
-setscratch()
+setscratch(void)
  {
          int r, k;
          char *dir;
_AT_@ -407,7 +407,7 @@ match(int num)
  }

  static int
-rematch(int num)
+rematch(void)
  {
          regoff_t off = matchs[0].rm_eo;

_AT_@ -451,18 +451,14 @@ getnum(void)

          for (ln = 0; isdigit(c = input()); ln += n) {
                  if (ln > INT_MAX/10)
- goto invalid;
+ error("invalid address");
                  n = c - '0';
                  ln *= 10;
                  if (INT_MAX - ln < n)
- goto invalid;
+ error("invalid address");
          }
          back(c);
          return ln;
-
-invalid:
- error("invalid address");
- return -1; /* not reached */
  }

  static int
_AT_@ -525,7 +521,7 @@ address(int *line)
                  num = isdigit(back(input())) ? getnum() : 1;
                  num *= sign;
                  if (INT_MAX - ln < num)
- goto invalid;
+ error("invalid address");
                  ln += num;
          }
          back(c);
_AT_@ -534,14 +530,10 @@ address(int *line)
                  error("invalid address");
          *line = ln;
          return 1;
-
-invalid:
- error("invalid address");
- return -1; /* not reached */
  }

  static void
-getlst()
+getlst(void)
  {
          int ln, c;

_AT_@ -589,7 +581,7 @@ deflines(int def1, int def2)
  }

  static void
-dowrite(char *fname, int trunc)
+dowrite(const char *fname, int trunc)
  {
          FILE *fp;
          int i, line;
_AT_@ -604,13 +596,14 @@ dowrite(char *fname, int trunc)
          curln = line2;
          if (fclose(fp))
                  error("input/output error");
- strcpy(savfname, fname);
+ if (strlcpy(savfname, fname, sizeof(savfname)))
+ error("file name too long");
          modflag = 0;
          curln = line;
  }

  static void
-doread(char *fname)
+doread(const char *fname)
  {
          size_t cnt;
          ssize_t n;
_AT_@ -734,8 +727,10 @@ getfname(char comm)
                  error("file name too long");
          } else {
                  *bp = '\0';
- if (savfname[0] == '\0' || comm == 'e' || comm == 'f')
- strcpy(savfname, fname);
+ if (savfname[0] == '\0' || comm == 'e' || comm == 'f') {
+ if (strlcpy(savfname, fname, sizeof(savfname)))
+ error("file name too long");
+ }
                  return fname;
          }
          return NULL; /* not reached */
_AT_@ -1010,7 +1005,7 @@ subline(int num, int nth)
          static size_t siz, cap;

          i = changed = siz = 0;
- for (m = match(num); m; m = rematch(num)) {
+ for (m = match(num); m; m = rematch()) {
                  addpre(&s, &cap, &siz);
                  changed |= addsub(&s, &cap, &siz, nth, ++i);
                  if (eol || bol)

Received on Fri Oct 07 2016 - 15:26:37 CEST

This archive was generated by hypermail 2.3.0 : Fri Oct 07 2016 - 15:36:15 CEST