Print this page
10476 file(1) could be smatch clean

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/file/magicutils.c
          +++ new/usr/src/cmd/file/magicutils.c
↓ open down ↓ 16 lines elided ↑ open up ↑
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
  24   24   */
  25   25  
  26   26  /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  27      -/*        All Rights Reserved   */
       27 +/*        All Rights Reserved   */
  28   28  
  29   29  /*      Copyright (c) 1987, 1988 Microsoft Corporation  */
  30   30  /*        All Rights Reserved   */
  31   31  
  32      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  33      -
  34   32  #include <stdio.h>
  35   33  #include <stdlib.h>
  36   34  #include <string.h>
  37   35  #include <ctype.h>
  38   36  #include <errno.h>
  39   37  #include <limits.h>
  40   38  #include <inttypes.h>
  41   39  #include <sys/types.h>
  42   40  #include <libintl.h>
  43   41  
↓ open down ↓ 142 lines elided ↑ open up ↑
 186  184                  }
 187  185          }
 188  186          *s = '\0';
 189  187          return (newstr);
 190  188  }
 191  189  
 192  190  /*
 193  191   * f_mkmtab - fills mtab array of magic table entries with
 194  192   *      values from the file magfile.
 195  193   *      May be called more than once if multiple magic
 196      - *      files were specified.
      194 + *      files were specified.
 197  195   *      Stores entries sequentially in one of two magic
 198  196   *      tables: mtab1, if first = 1; mtab2 otherwise.
 199  197   *
 200  198   *      If -c option is specified, cflg is non-zero, and
 201  199   *      f_mkmtab() reports on errors in the magic file.
 202  200   *
 203  201   *      Two magic tables may need to be created.  The first
 204  202   *      one (mtab1) contains magic entries to be checked before
 205  203   *      the programmatic default position-sensitive tests in
 206  204   *      def_position_tests().
↓ open down ↓ 29 lines elided ↑ open up ↑
 236  234                  mend = mend1;
 237  235                  ep = ep1;
 238  236          } else {
 239  237                  mtab = mtab2;
 240  238                  mend = mend2;
 241  239                  ep = ep2;
 242  240          }
 243  241  
 244  242          /* mtab may have been allocated on a previous f_mkmtab call */
 245  243          if (mtab == (Entry *)NULL) {
 246      -                if ((mtab = calloc(sizeof (Entry), NENT)) == NULL) {
      244 +                if ((mtab = calloc(NENT, sizeof (Entry))) == NULL) {
 247  245                          int err = errno;
 248  246                          (void) fprintf(stderr, gettext("%s: malloc "
 249  247                              "failed: %s\n"), File, strerror(err));
 250  248                          return (-1);
 251  249                  }
 252  250  
 253  251                  ep = mtab;
 254  252                  mend = &mtab[NENT];
 255  253          }
 256  254  
↓ open down ↓ 101 lines elided ↑ open up ↑
 358  356                                                          break;
 359  357                                                  default:
 360  358                                                          ep->e_type = LONG;
 361  359                                                          break;
 362  360                                          }
 363  361                                  }
 364  362                                  break;
 365  363                          case 'l':
 366  364                                  if (*(p+1) == 'l') {    /* llong */
 367  365                                          ep->e_type = LLONG;
 368      -                                } else {                /* long */
      366 +                                } else {                /* long */
 369  367                                          ep->e_type = LONG;
 370  368                                  }
 371  369                                  break;
 372  370                          case 's':
 373  371                                  if (*(p+1) == 'h') {
 374  372                                          /* short */
 375  373                                          ep->e_type = SHORT;
 376  374                                  } else {
 377  375                                          /* s or string */
 378  376                                          ep->e_type = STR;
↓ open down ↓ 151 lines elided ↑ open up ↑
 530  528  /*
 531  529   * Check for Magic Table entries in the file.
 532  530   *
 533  531   * Since there may be two sets of magic tables, first = 1
 534  532   * for the first magic table (mtab1) and 0 for the second magic
 535  533   * table (mtab2).
 536  534   */
 537  535  int
 538  536  f_ckmtab(char *buf, int bufsize, int first)
 539  537  {
 540      -        int             result;
      538 +        int             result;
 541  539          Entry           *mtab;
 542  540          Entry           *ep;
 543  541          char            *p;
 544  542          int             lev1 = 0;
 545  543  
 546  544          uint16_t        u16_val;
 547  545          uint32_t        u32_val;
 548  546          uint64_t        u64_val;
 549  547  
 550  548          if (first) {
↓ open down ↓ 291 lines elided ↑ open up ↑
 842  840                          continue;
 843  841                  }
 844  842                  if (lev1)
 845  843                          (void) putchar(' ');
 846  844                  if (ep->e_opcode & SUB) {
 847  845                          switch (ep->e_type) {
 848  846                          case LLONG:
 849  847  #ifdef XPG4
 850  848                                  if (ep->e_mask == 0) {
 851  849                                          (void) printf(ep->e_str,
 852      -                                                (int64_t)u64_val);
      850 +                                            (int64_t)u64_val);
 853  851                                          break;
 854  852                                  }
 855  853  #endif  /* XPG4 */
 856  854                                  /*FALLTHROUGH*/
 857  855                          case ULLONG:
 858  856                                  (void) printf(ep->e_str, u64_val);
 859  857                                  break;
 860  858                          case LONG:
 861  859  #ifdef XPG4
 862  860                                  if (ep->e_mask == 0) {
 863  861                                          (void) printf(ep->e_str,
 864      -                                                (int32_t)u64_val);
      862 +                                            (int32_t)u64_val);
 865  863                                          break;
 866  864                                  }
 867  865  #endif  /* XPG4 */
 868  866                                  /*FALLTHROUGH*/
 869  867                          case ULONG:
 870  868                                  (void) printf(ep->e_str,
 871  869                                      (uint32_t)u64_val);
 872  870                                  break;
 873  871                          case SHORT:
 874  872  #ifdef XPG4
 875  873                                  if (ep->e_mask == 0) {
 876  874                                          (void) printf(ep->e_str,
 877      -                                                (int16_t)u64_val);
      875 +                                            (int16_t)u64_val);
 878  876                                          break;
 879  877                                  }
 880  878  #endif  /* XPG4 */
 881  879                                  /*FALLTHROUGH*/
 882  880                          case USHORT:
 883  881                                  (void) printf(ep->e_str,
 884  882                                      (uint16_t)u64_val);
 885  883                                  break;
 886  884                          case BYTE:
 887  885  #ifdef XPG4
 888  886                                  if (ep->e_mask == 0) {
 889  887                                          (void) printf(ep->e_str,
 890      -                                                (int8_t)u64_val);
      888 +                                            (int8_t)u64_val);
 891  889                                          break;
 892  890                                  }
 893  891  #endif  /* XPG4 */
 894  892                                  /*FALLTHROUGH*/
 895  893                          case UBYTE:
 896  894                                  (void) printf(ep->e_str,
 897  895                                      (uint8_t)u64_val);
 898  896                                  break;
 899  897                          case STR:
 900  898                                  /*
↓ open down ↓ 163 lines elided ↑ open up ↑
1064 1062   *      tables, mtab1 and mtab2, if any exist.
1065 1063   */
1066 1064  void
1067 1065  f_prtmtab(void)
1068 1066  {
1069 1067          Entry   *mtab;
1070 1068          Entry   *ep;
1071 1069          int     count;
1072 1070  
1073 1071          (void) printf("%-7s %-7s %-10s %-7s %-11s %s\n",
1074      -                "level", "off", "type", "opcode", "value", "string");
     1072 +            "level", "off", "type", "opcode", "value", "string");
1075 1073          for (mtab = mtab1, count = 1; count <= 2; count++, mtab = mtab2) {
1076 1074                  if (mtab == (Entry *)NULL) {
1077 1075                          continue;
1078 1076                  }
1079 1077                  for (ep = mtab; ep->e_off != -1L; ep++) {
1080 1078                          (void) printf("%-7d %-7ld %-10s %-7c ",
1081 1079                              ep->e_level,
1082 1080                              ep->e_off, type_to_name(ep),
1083 1081                              op_to_name(ep->e_opcode));
1084 1082                          if (ep->e_type == STR) {
↓ open down ↓ 58 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX