[RTEMS Project] #4864: Bitwise operator applied to a signed operand

RTEMS trac trac at rtems.org
Thu Feb 23 12:40:00 UTC 2023


#4864: Bitwise operator applied to a signed operand
----------------------------+---------------------------
  Reporter:  Daniel Páscoa  |      Owner:  (none)
      Type:  defect         |     Status:  new
  Priority:  normal         |  Milestone:
 Component:  admin          |    Version:  6
  Severity:  normal         |   Keywords:  qualification
Blocked By:                 |   Blocking:
----------------------------+---------------------------
 Bitwise operators should not be applied to signed operand.

 Most built-in bitwise operators (~, >>, >>=, &, &=, ^, ^=, |, and |=) have
 implementation-dependent results when performed on signed operands, and
 bitwise left shift (<< and <<=) have undefined behavior when performed on
 negative operands. Therefore, bitwise operations should not be performed
 on signed operands.

 The RTEMS SW Eng. Manual seems not to have a rule listed for this, but
 perhaps it shall be added.

 For instance, the following cases shall be checked:

 **cpukit\include\rtems\score\processormask.h** (line 318, 336):
    return (uint32_t) (bits >> (32 * (index % _BITSET_BITS) / 32));
 with bits defined as long and
    mask->__bits[ __bitset_words( index ) ] = ((long) bits) << (32 * (index
    % _BITSET_BITS) / 32);

 These seem problematic, but most likely in systems where the actual number
 of processors is equal to CPU_MAXIMUM_PROCESSORS equal to 32! Since these
 belong to inline functions, they are not included in the RTEMS libraries,
 but a user can include this file and use them.

 **cpukit\include\rtems\score\timestampimpl.h** (line 238):
    return (*_time >> 32); where time is of type int64_t.

 Shifting right a signed negative number is implementation-defined. gcc for
 sparc implements it as an aritmetic shift right.


 **Additional Notes:**
 This ticket was raised as an outcome of the Independent SW Verification
 and Validation (ISVV) for ESA-promoted RTEMS SMP Qualification Data Packs
 (https://rtems-qual.io.esa.int). The original ISVV reference for this
 issue is RTEMS-SMP-CODE-VER-078.

--
Ticket URL: <http://devel.rtems.org/ticket/4864>
RTEMS Project <http://www.rtems.org/>
RTEMS Project


More information about the bugs mailing list