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

Diff for /src/usr.bin/col/col.c between version 1.11 and 1.12

version 1.11, 2009/10/27 23:59:36 version 1.12, 2014/10/08 19:59:58
Line 85 
Line 85 
 void    flush_blanks(void);  void    flush_blanks(void);
 void    free_line(LINE *);  void    free_line(LINE *);
 void    usage(void);  void    usage(void);
 void   *xmalloc(void *, size_t);  void   *xreallocarray(void *, size_t, size_t);
   
 CSET    last_set;               /* char_set of last char printed */  CSET    last_set;               /* char_set of last char printed */
 LINE   *lines;  LINE   *lines;
Line 263 
Line 263 
                 if (l->l_line_len + 1 >= l->l_lsize) {                  if (l->l_line_len + 1 >= l->l_lsize) {
                         int need;                          int need;
   
                         need = l->l_lsize ? l->l_lsize * 2 : 90;                          need = l->l_lsize ? l->l_lsize : 45;
                         l->l_line = (CHAR *)xmalloc((void *) l->l_line,                          l->l_line = xreallocarray(l->l_line,
                             (unsigned) need * sizeof(CHAR));                              need, 2 * sizeof(CHAR));
                         l->l_lsize = need;                          l->l_lsize = need * 2;
                 }                  }
                 c = &l->l_line[l->l_line_len++];                  c = &l->l_line[l->l_line_len++];
                 c->c_char = ch;                  c->c_char = ch;
Line 379 
Line 379 
                  */                   */
                 if (l->l_lsize > sorted_size) {                  if (l->l_lsize > sorted_size) {
                         sorted_size = l->l_lsize;                          sorted_size = l->l_lsize;
                         sorted = (CHAR *)xmalloc((void *)sorted,                          sorted = xreallocarray(sorted,
                             (unsigned)sizeof(CHAR) * sorted_size);                              sorted_size, sizeof(CHAR));
                 }                  }
                 if (l->l_max_col >= count_size) {                  if (l->l_max_col >= count_size) {
                         count_size = l->l_max_col + 1;                          count_size = l->l_max_col + 1;
                         count = (int *)xmalloc((void *)count,                          count = xreallocarray(count,
                             (unsigned)sizeof(int) * count_size);                              count_size, sizeof(int));
                 }                  }
                 memset((char *)count, 0, sizeof(int) * l->l_max_col + 1);                  memset((char *)count, 0, sizeof(int) * l->l_max_col + 1);
                 for (i = nchars, c = l->l_line; --i >= 0; c++)                  for (i = nchars, c = l->l_line; --i >= 0; c++)
Line 466 
Line 466 
         int i;          int i;
   
         if (!line_freelist) {          if (!line_freelist) {
                 l = (LINE *)xmalloc(NULL, sizeof(LINE) * NALLOC);                  l = xreallocarray(NULL, NALLOC, sizeof(LINE));
                 line_freelist = l;                  line_freelist = l;
                 for (i = 1; i < NALLOC; i++, l++)                  for (i = 1; i < NALLOC; i++, l++)
                         l->l_next = l + 1;                          l->l_next = l + 1;
Line 488 
Line 488 
 }  }
   
 void *  void *
 xmalloc(void *p, size_t size)  xreallocarray(void *p, size_t n, size_t size)
 {  {
   
         if (!(p = (void *)realloc(p, size)))          if (!(p = reallocarray(p, n, size)))
                 err(1, "realloc failed");                  err(1, "realloc failed");
         return (p);          return (p);
 }  }

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12