Print this page
5083 avoid undefined order of operations in assignments

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/scadm/sparc/mpxu/common/smq.c
          +++ new/usr/src/cmd/scadm/sparc/mpxu/common/smq.c
↓ open down ↓ 16 lines elided ↑ open up ↑
  17   17   * fields enclosed by brackets "[]" replaced with your own identifying
  18   18   * information: Portions Copyright [yyyy] [name of copyright owner]
  19   19   *
  20   20   * CDDL HEADER END
  21   21   */
  22   22  /*
  23   23   * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
  24   24   * Use is subject to license terms.
  25   25   */
  26   26  
  27      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  28      -
  29   27  /*
  30   28   * smq.c: to provide a message queue system for scadm functions (used in the
  31   29   * firmware download context where BP messages, received from the service
  32   30   * processor, are stored in the message queue)
  33   31   *
  34   32   * these routines come from the libxposix library
  35   33   */
  36   34  
  37   35  #include <sys/types.h>
  38   36  #include <time.h>
↓ open down ↓ 45 lines elided ↑ open up ↑
  84   82  
  85   83          /* Wait for message */
  86   84          (void) xsem_wait(&smq->smq_msgAvail);
  87   85  
  88   86          if (smq->smq_count == 0)
  89   87                  return (SMQ_ERROR);
  90   88  
  91   89          /* Copy messaged into queue */
  92   90          *msg = *smq->smq_head;
  93   91  
  94      -        /* Increment Head */
  95      -        smq->smq_head = smq->smq_head++;
       92 +        smq->smq_head++;
  96   93          if ((unsigned long)smq->smq_head > ((unsigned long)smq->smq_msgBuffer +
  97   94              (unsigned long)(smq->smq_depth * sizeof (smq_msg_t)))) {
  98   95                  smq->smq_head = smq->smq_msgBuffer;
  99   96          }
 100   97          smq->smq_count--;
 101   98  
 102   99          return (0);
 103  100  }
 104  101  
 105  102  
↓ open down ↓ 2 lines elided ↑ open up ↑
 108  105  {
 109  106          if ((smq->smq_control & SMQ_VALID_SMQ_MASK) != SMQ_VALID_SMQ)
 110  107                  return (SMQ_INVALID);
 111  108  
 112  109          if (smq->smq_count == smq->smq_depth)
 113  110                  return (SMQ_FULL);
 114  111  
 115  112          /* Copy messaged into queue */
 116  113          *smq->smq_tail = *msg;
 117  114  
 118      -        /* Increment Tail */
 119      -        smq->smq_tail = smq->smq_tail++;
      115 +        smq->smq_tail++;
 120  116          if ((unsigned long)smq->smq_tail > ((unsigned long)smq->smq_msgBuffer +
 121  117              (unsigned long)(smq->smq_depth * sizeof (smq_msg_t)))) {
 122  118                  smq->smq_tail = smq->smq_msgBuffer;
 123  119          }
 124  120  
 125  121          smq->smq_count++;
 126  122          (void) xsem_post(&smq->smq_msgAvail);
 127  123  
 128  124          return (0);
 129  125  }
↓ open down ↓ 38 lines elided ↑ open up ↑
 168  164  
 169  165          if (Status != 0)
 170  166                  return (SMQ_ERROR);
 171  167  
 172  168          if (smq->smq_count == 0)
 173  169                  return (SMQ_ERROR);
 174  170  
 175  171          /* Copy messaged into queue */
 176  172          *msg = *smq->smq_head;
 177  173  
 178      -        /* Increment Head */
 179      -        smq->smq_head = smq->smq_head++;
      174 +        smq->smq_head++;
 180  175          if ((unsigned long)smq->smq_head > ((unsigned long)smq->smq_msgBuffer +
 181  176              (unsigned long)(smq->smq_depth * sizeof (smq_msg_t)))) {
 182  177                  smq->smq_head = smq->smq_msgBuffer;
 183  178          }
 184  179          smq->smq_count--;
 185  180  
 186  181  
 187  182          return (0);
 188  183  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX