[BACK]Return to lib.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / awk

Diff for /src/usr.bin/awk/lib.c between version 1.30 and 1.31

version 1.30, 2020/06/10 21:02:53 version 1.31, 2020/06/10 21:03:36
Line 59 
Line 59 
   
 void recinit(unsigned int n)  void recinit(unsigned int n)
 {  {
         if ( (record = (char *) malloc(n)) == NULL          if ( (record = malloc(n)) == NULL
           || (fields = (char *) malloc(n+1)) == NULL            || (fields = malloc(n+1)) == NULL
           || (fldtab = (Cell **) calloc(nfields+2, sizeof(Cell *))) == NULL            || (fldtab = calloc(nfields+2, sizeof(*fldtab))) == NULL
           || (fldtab[0] = (Cell *) malloc(sizeof(Cell))) == NULL )            || (fldtab[0] = malloc(sizeof(**fldtab))) == NULL)
                 FATAL("out of space for $0 and fields");                  FATAL("out of space for $0 and fields");
         *record = '\0';          *record = '\0';
         *fldtab[0] = dollar0;          *fldtab[0] = dollar0;
Line 77 
Line 77 
         int i;          int i;
   
         for (i = n1; i <= n2; i++) {          for (i = n1; i <= n2; i++) {
                 fldtab[i] = (Cell *) malloc(sizeof (struct Cell));                  fldtab[i] = malloc(sizeof(**fldtab));
                 if (fldtab[i] == NULL)                  if (fldtab[i] == NULL)
                         FATAL("out of space in makefields %d", i);                          FATAL("out of space in makefields %d", i);
                 *fldtab[i] = dollar1;                  *fldtab[i] = dollar1;
                 snprintf(temp, sizeof temp, "%d", i);                  snprintf(temp, sizeof(temp), "%d", i);
                 fldtab[i]->nval = tostring(temp);                  fldtab[i]->nval = tostring(temp);
         }          }
 }  }
Line 217 
Line 217 
                 fa *pfa = makedfa(rs, 1);                  fa *pfa = makedfa(rs, 1);
                 found = fnematch(pfa, inf, &buf, &bufsize, recsize);                  found = fnematch(pfa, inf, &buf, &bufsize, recsize);
                 if (found)                  if (found)
                         *patbeg = 0;                          setptr(patbeg, '\0');
         } else {          } else {
                 if ((sep = *rs) == 0) {                  if ((sep = *rs) == 0) {
                         sep = '\n';                          sep = '\n';
Line 261 
Line 261 
         char *s, temp[50];          char *s, temp[50];
         extern Array *ARGVtab;          extern Array *ARGVtab;
   
         snprintf(temp, sizeof temp, "%d", n);          snprintf(temp, sizeof(temp), "%d", n);
         if (lookup(temp, ARGVtab) == NULL)          if (lookup(temp, ARGVtab) == NULL)
                 return NULL;                  return NULL;
         x = setsymtab(temp, "", 0.0, STR, ARGVtab);          x = setsymtab(temp, "", 0.0, STR, ARGVtab);
Line 306 
Line 306 
         n = strlen(r);          n = strlen(r);
         if (n > fieldssize) {          if (n > fieldssize) {
                 xfree(fields);                  xfree(fields);
                 if ((fields = (char *) malloc(n+2)) == NULL) /* possibly 2 final \0s */                  if ((fields = malloc(n+2)) == NULL) /* possibly 2 final \0s */
                         FATAL("out of space for fields in fldbld %d", n);                          FATAL("out of space for fields in fldbld %d", n);
                 fieldssize = n;                  fieldssize = n;
         }          }
Line 449 
Line 449 
                 nf = n;                  nf = n;
         s = (nf+1) * (sizeof (struct Cell *));  /* freebsd: how much do we need? */          s = (nf+1) * (sizeof (struct Cell *));  /* freebsd: how much do we need? */
         if (s / sizeof(struct Cell *) - 1 == nf) /* didn't overflow */          if (s / sizeof(struct Cell *) - 1 == nf) /* didn't overflow */
                 fldtab = (Cell **) realloc(fldtab, s);                  fldtab = realloc(fldtab, s);
         else                                    /* overflow sizeof int */          else                                    /* overflow sizeof int */
                 xfree(fldtab);  /* make it null */                  xfree(fldtab);  /* make it null */
         if (fldtab == NULL)          if (fldtab == NULL)
Line 469 
Line 469 
         n = strlen(rec);          n = strlen(rec);
         if (n > fieldssize) {          if (n > fieldssize) {
                 xfree(fields);                  xfree(fields);
                 if ((fields = (char *) malloc(n+1)) == NULL)                  if ((fields = malloc(n+1)) == NULL)
                         FATAL("out of space for fields in refldbld %d", n);                          FATAL("out of space for fields in refldbld %d", n);
                 fieldssize = n;                  fieldssize = n;
         }          }

Legend:
Removed from v.1.30  
changed lines
  Added in v.1.31