Print this page
5083 avoid undefined order of operations in assignments

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/troff/troff.d/t6.c
          +++ new/usr/src/cmd/troff/troff.d/t6.c
↓ open down ↓ 29 lines elided ↑ open up ↑
  30   30  /*
  31   31   * University Copyright- Copyright (c) 1982, 1986, 1988
  32   32   * The Regents of the University of California
  33   33   * All Rights Reserved
  34   34   *
  35   35   * University Acknowledgment- Portions of this document are derived from
  36   36   * software developed by the University of California, Berkeley, and its
  37   37   * contributors.
  38   38   */
  39   39  
  40      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  41      -
  42   40  /*
  43   41   * t6.c
  44      - * 
       42 + *
  45   43   * width functions, sizes and fonts
  46   44   */
  47   45  
  48   46  #include "tdef.h"
  49   47  #include "dev.h"
  50   48  #include <ctype.h>
  51   49  #include "ext.h"
  52   50  
  53   51  /* fitab[f][c] is 0 if c is not on font f */
  54   52          /* if it's non-zero, c is in fontab[f] at position
↓ open down ↓ 36 lines elided ↑ open up ↑
  91   89                          return(0);
  92   90          }
  93   91          if (i==ohc)
  94   92                  return(0);
  95   93          i = trtab[i];
  96   94          if (i < 32)
  97   95                  return(0);
  98   96          if (sfbits(j) == oldbits) {
  99   97                  xfont = pfont;
 100   98                  xpts = ppts;
 101      -        } else 
       99 +        } else
 102  100                  xbits(j, 0);
 103  101          if (widcache[i-32].fontpts == (xfont<<8) + xpts && !setwdf)
 104  102                  k = widcache[i-32].width;
 105  103          else {
 106  104                  k = getcw(i-32);
 107  105                  if (bd)
 108  106                          k += (bd - 1) * HOR;
 109  107                  if (cs)
 110  108                          k = cs;
 111  109          }
↓ open down ↓ 67 lines elided ↑ open up ↑
 179  177          p = fontab[xfont];
 180  178          if (setwdf)
 181  179                  numtab[CT].val |= kerntab[xfont][j];
 182  180          k = *(p + j);
 183  181   g1:
 184  182          if (!bd)
 185  183                  bd = bdtab[xfont];
 186  184          if (cs = cstab[xfont]) {
 187  185                  nocache = 1;
 188  186                  if (ccs = ccstab[xfont])
 189      -                        x = ccs; 
 190      -                else 
      187 +                        x = ccs;
      188 +                else
 191  189                          x = xpts;
 192  190                  cs = (cs * EMPTS(x)) / 36;
 193  191          }
 194  192          k = ((k&BYTEMASK) * xpts + (Unitwidth / 2)) / Unitwidth;
 195  193          if (nocache|bd)
 196  194                  widcache[i].fontpts = 0;
 197  195          else {
 198  196                  widcache[i].fontpts = (xfont<<8) + xpts;
 199  197                  widcache[i].width = k;
 200  198          }
↓ open down ↓ 264 lines elided ↑ open up ↑
 465  463  
 466  464  
 467  465  int
 468  466  setfont(a)
 469  467  int     a;
 470  468  {
 471  469          int     i, j;
 472  470  
 473  471          if (a)
 474  472                  i = getrq();
 475      -        else 
      473 +        else
 476  474                  i = getsn();
 477  475          if (!i || i == 'P') {
 478  476                  j = font1;
 479  477                  goto s0;
 480  478          }
 481  479          if (i == 'S' || i == '0')
 482  480                  return (0);
 483  481          if ((j = findft(i)) == -1)
 484  482                  if ((j = setfp(0, i, 0)) == -1) /* try to put it in position 0 */
 485  483                          return (0);
↓ open down ↓ 7 lines elided ↑ open up ↑
 493  491  
 494  492  
 495  493  int
 496  494  setwd()
 497  495  {
 498  496          int     base, wid;
 499  497          tchar i;
 500  498          int     delim, emsz, k;
 501  499          int     savhp, savapts, savapts1, savfont, savfont1, savpts, savpts1;
 502  500  
 503      -        base = numtab[ST].val = numtab[ST].val = wid = numtab[CT].val = 0;
      501 +        base = numtab[ST].val = wid = numtab[CT].val = 0;
 504  502          if (ismot(i = getch()))
 505  503                  return (0);
 506  504          delim = cbits(i);
 507  505          savhp = numtab[HP].val;
 508  506          numtab[HP].val = 0;
 509  507          savapts = apts;
 510  508          savapts1 = apts1;
 511  509          savfont = font;
 512  510          savfont1 = font1;
 513  511          savpts = pts;
↓ open down ↓ 4 lines elided ↑ open up ↑
 518  516                  wid += k;
 519  517                  numtab[HP].val += k;
 520  518                  if (!ismot(i)) {
 521  519                          emsz = POINT * xpts;
 522  520                  } else if (isvmot(i)) {
 523  521                          k = absmot(i);
 524  522                          if (isnmot(i))
 525  523                                  k = -k;
 526  524                          base -= k;
 527  525                          emsz = 0;
 528      -                } else 
      526 +                } else
 529  527                          continue;
 530  528                  if (base < numtab[SB].val)
 531  529                          numtab[SB].val = base;
 532  530                  if ((k = base + emsz) > numtab[ST].val)
 533  531                          numtab[ST].val = k;
 534  532          }
 535  533          setn1(wid, 0, (tchar) 0);
 536  534          numtab[HP].val = savhp;
 537  535          apts = savapts;
 538  536          apts1 = savapts1;
↓ open down ↓ 94 lines elided ↑ open up ↑
 633  631                  if ((lf & (LFFI|LFFL)) && lg != 2) {
 634  632                          k = getch0();
 635  633                          if (cbits(k)=='i' && (lf&LFFI))
 636  634                                  j = LIG_FFI;
 637  635                          else if (cbits(k)=='l' && (lf&LFFL))
 638  636                                  j = LIG_FFL;
 639  637                          else {
 640  638                                  *pbp++ = k;
 641  639                                  j = LIG_FF;
 642  640                          }
 643      -                } else 
      641 +                } else
 644  642                          j = LIG_FF;
 645  643          } else {
 646  644                  *pbp++ = j;
 647  645                  j = i;
 648  646          }
 649  647          return(i & SFMASK | j);
 650  648  }
 651  649  
 652  650  
 653  651  int
↓ open down ↓ 57 lines elided ↑ open up ↑
 711  709          /* have to reset the fitab pointer because the width may be different */
 712  710          fitab[pos] = (char *) fontab[pos] + 3 * (fontbase[pos]->nwfont & BYTEMASK);
 713  711          if ((fontbase[pos]->nwfont & BYTEMASK) > n) {
 714  712                  errprint(gettext("Font %s too big for position %d"), shortname,
 715  713                          pos);
 716  714                  return(-1);
 717  715          }
 718  716          fontbase[pos]->nwfont = n;      /* so can load a larger one again later */
 719  717          close(k);
 720  718          if (pos == smnt) {
 721      -                smnt = 0; 
 722      -                sbold = 0; 
      719 +                smnt = 0;
      720 +                sbold = 0;
 723  721          }
 724  722          if ((fontlab[pos] = f) == 'S')
 725  723                  smnt = pos;
 726  724          bdtab[pos] = cstab[pos] = ccstab[pos] = 0;
 727  725                  /* if there is a directory, no place to store its name. */
 728  726                  /* if position isn't zero, no place to store its value. */
 729  727                  /* only time a FONTPOS is pushed back is if it's a */
 730  728                  /* standard font on position 0 (i.e., mounted implicitly. */
 731  729                  /* there's a bug here:  if there are several input lines */
 732  730                  /* that look like .ft XX in short successtion, the output */
↓ open down ↓ 36 lines elided ↑ open up ↑
 769  767  casebd()
 770  768  {
 771  769          int     i, j, k;
 772  770  
 773  771          zapwcache(0);
 774  772          k = 0;
 775  773  bd0:
 776  774          if (skip() || !(i = getrq()) || (j = findft(i)) == -1) {
 777  775                  if (k)
 778  776                          goto bd1;
 779      -                else 
      777 +                else
 780  778                          return (0);
 781  779          }
 782  780          if (j == smnt) {
 783  781                  k = smnt;
 784  782                  goto bd0;
 785  783          }
 786  784          if (k) {
 787  785                  sbold = j;
 788  786                  j = k;
 789  787          }
↓ open down ↓ 13 lines elided ↑ open up ↑
 803  801          int     i;
 804  802  
 805  803          skip();
 806  804          vflag++;
 807  805          dfact = INCH; /* default scaling is points! */
 808  806          dfactd = 72;
 809  807          res = VERT;
 810  808          i = inumb(&lss);
 811  809          if (nonumb)
 812  810                  i = lss1;
 813      -        if (i < VERT) 
      811 +        if (i < VERT)
 814  812                  i = VERT;
 815  813          lss1 = lss;
 816  814          lss = i;
 817  815  
 818  816          return (0);
 819  817  }
 820  818  
 821  819  
 822  820  int
 823  821  casess()
↓ open down ↓ 37 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX