Print this page
5083 avoid undefined order of operations in assignments

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/troff/nroff.d/n6.c
          +++ new/usr/src/cmd/troff/nroff.d/n6.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  #include "tdef.h"
  43   41  #include "tw.h"
  44   42  #include "ext.h"
  45   43  #include <ctype.h>
  46   44  
  47   45  /*
  48   46   * n6.c -- width functions, sizes and fonts
  49   47  */
  50   48  
  51   49  int     bdtab[NFONT+1] ={ 0, 0, 0, 3, 3, 0, };
↓ open down ↓ 185 lines elided ↑ open up ↑
 237  235  
 238  236  
 239  237  int
 240  238  setfont(a)
 241  239  int     a;
 242  240  {
 243  241          int     i, j;
 244  242  
 245  243          if (a)
 246  244                  i = getrq();
 247      -        else 
      245 +        else
 248  246                  i = getsn();
 249  247          if (!i || i == 'P') {
 250  248                  j = font1;
 251  249                  goto s0;
 252  250          }
 253  251          if (i == 'S' || i == '0')
 254  252                  return (0);
 255  253          if ((j = findft(i, fontlab)) == -1)
 256  254                  return (0);
 257  255  s0:
↓ open down ↓ 6 lines elided ↑ open up ↑
 264  262  
 265  263  
 266  264  int
 267  265  setwd()
 268  266  {
 269  267          int     base, wid;
 270  268          tchar i;
 271  269          int     delim, emsz, k;
 272  270          int     savhp, savapts, savapts1, savfont, savfont1, savpts, savpts1;
 273  271  
 274      -        base = numtab[ST].val = numtab[ST].val = wid = numtab[CT].val = 0;
      272 +        base = numtab[ST].val = wid = numtab[CT].val = 0;
 275  273          if (ismot(i = getch()))
 276  274                  return (0);
 277  275          delim = cbits(i);
 278  276          savhp = numtab[HP].val;
 279  277          numtab[HP].val = 0;
 280  278          savapts = apts;
 281  279          savapts1 = apts1;
 282  280          savfont = font;
 283  281          savfont1 = font1;
 284  282          savpts = pts;
↓ open down ↓ 4 lines elided ↑ open up ↑
 289  287                  wid += k;
 290  288                  numtab[HP].val += k;
 291  289                  if (!ismot(i)) {
 292  290                          emsz = (INCH * pts + 36) / 72;
 293  291                  } else if (isvmot(i)) {
 294  292                          k = absmot(i);
 295  293                          if (isnmot(i))
 296  294                                  k = -k;
 297  295                          base -= k;
 298  296                          emsz = 0;
 299      -                } else 
      297 +                } else
 300  298                          continue;
 301  299                  if (base < numtab[SB].val)
 302  300                          numtab[SB].val = base;
 303  301                  if ((k = base + emsz) > numtab[ST].val)
 304  302                          numtab[ST].val = k;
 305  303          }
 306  304          setn1(wid, 0, (tchar) 0);
 307  305          numtab[HP].val = savhp;
 308  306          apts = savapts;
 309  307          apts1 = savapts1;
↓ open down ↓ 117 lines elided ↑ open up ↑
 427  425  int
 428  426  casebd()
 429  427  {
 430  428          int     i, j, k;
 431  429  
 432  430          k = 0;
 433  431  bd0:
 434  432          if (skip() || !(i = getrq()) || (j = findft(i)) == -1) {
 435  433                  if (k)
 436  434                          goto bd1;
 437      -                else 
      435 +                else
 438  436                          return (0);
 439  437          }
 440  438          if (j == smnt) {
 441  439                  k = smnt;
 442  440                  goto bd0;
 443  441          }
 444  442          if (k) {
 445  443                  sbold = j;
 446  444                  j = k;
 447  445          }
↓ open down ↓ 61 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX