Print this page
5083 avoid undefined order of operations in assignments

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/sun4u/serengeti/io/sghsc.c
          +++ new/usr/src/uts/sun4u/serengeti/io/sghsc.c
↓ open down ↓ 1775 lines elided ↑ open up ↑
1776 1776   * Returns DDI_FAILURE if the buffer is full, DDI_SUCCESS otherwise
1777 1777   */
1778 1778  static int
1779 1779  sghsc_rb_put(sghsc_rb_head_t *rb_head, sghsc_event_t *event)
1780 1780  {
1781 1781          if (rb_head->state == SGHSC_RB_FULL)
1782 1782                  return (DDI_FAILURE);
1783 1783  
1784 1784          rb_head->buf[rb_head->put_idx] = *event;
1785 1785  
1786      -        rb_head->put_idx = ++rb_head->put_idx & (rb_head->size - 1);
     1786 +        rb_head->put_idx = (rb_head->put_idx + 1) & (rb_head->size - 1);
1787 1787  
1788 1788          if (rb_head->put_idx == rb_head->get_idx)
1789 1789                  rb_head->state = SGHSC_RB_FULL;
1790 1790          else
1791 1791                  rb_head->state = SGHSC_RB_FLOAT;
1792 1792  
1793 1793          return (DDI_SUCCESS);
1794 1794  }
1795 1795  /*
1796 1796   * sghsc_rb_get()
↓ open down ↓ 2 lines elided ↑ open up ↑
1799 1799   */
1800 1800  static int
1801 1801  sghsc_rb_get(sghsc_rb_head_t *rb_head, sghsc_event_t *event)
1802 1802  {
1803 1803  
1804 1804          if (rb_head->state == SGHSC_RB_EMPTY)
1805 1805                  return (DDI_FAILURE);
1806 1806  
1807 1807          *event = rb_head->buf[rb_head->get_idx];
1808 1808  
1809      -        rb_head->get_idx = ++rb_head->get_idx & (rb_head->size - 1);
     1809 +        rb_head->get_idx = (rb_head->get_idx + 1) & (rb_head->size - 1);
1810 1810  
1811 1811          if (rb_head->get_idx == rb_head->put_idx)
1812 1812                  rb_head->state = SGHSC_RB_EMPTY;
1813 1813          else
1814 1814                  rb_head->state = SGHSC_RB_FLOAT;
1815 1815  
1816 1816          return (DDI_SUCCESS);
1817 1817  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX