Project

General

Profile

Actions

Bug #3497

closed

Mgmt/Nfd/TestControlCommand/Face{Enable,Disable}LocalControl undefined behavior

Added by Davide Pesavento over 8 years ago. Updated over 7 years ago.

Status:
Closed
Priority:
Low
Assignee:
-
Category:
Tests
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
2.00 h

Description

FaceEnableLocalControl and FaceDisableLocalControl test cases perform the following illegal cast:

static_cast<LocalControlFeature>(666)

This is undefined behavior because 666 is not within the range of the values of the enum type LocalControlFeature. The standard says:

[expr.static.cast]

  1. A value of integral or enumeration type can be explicitly converted to a complete enumeration type. The value is unchanged if the original value is within the range of the enumeration values. Otherwise, the behavior is undefined.

[dcl.enum]

  1. For an enumeration whose underlying type is fixed, the values of the enumeration are the values of the underlying type. Otherwise, for an enumeration where emin is the smallest enumerator and emax is the largest, the values of the enumeration are the values in the range bmin to bmax, defined as follows: Let K be 1 for a two's complement representation and 0 for a one's complement or sign-magnitude representation. bmax is the smallest value greater than or equal to max(|emin| − K, |emax|) and equal to 2M − 1, where M is a non-negative integer. bmin is zero if emin is non-negative and −(bmax + K) otherwise.

See also http://stackoverflow.com/questions/18195312/what-happens-if-you-static-cast-invalid-value-to-enum-class


Related issues 1 (0 open1 closed)

Related to ndn-cxx - Bug #3974: Unsafe casts in ndn::nfd::*::wireDecode()ClosedJunxiao Shi

Actions
Actions #1

Updated by Junxiao Shi over 8 years ago

This is just another Halt-and-Catch-Fire bug.

I see no value in fixing it because (1) it works fine for now (2) the test case will be gone after #3226.

Actions #2

Updated by Davide Pesavento about 8 years ago

  • Subject changed from ManagementNfdControlCommand/Face{Enable,Disable}LocalControl undefined behavior to Mgmt/Nfd/TestControlCommand/Face{Enable,Disable}LocalControl undefined behavior
  • Target version deleted (v0.5)
Actions #3

Updated by Eric Newberry almost 8 years ago

Is this still an issue after #3731?

Actions #4

Updated by Junxiao Shi almost 8 years ago

  • Target version set to v0.6
  • Estimated time set to 2.00 h

The offending test case is still there because FaceEnableLocalControl and FaceDisableLocalControl commands are still there. I suggest deleting these deprecated commands. This solution is subject to approval at NFD call.

Actions #5

Updated by Junxiao Shi over 7 years ago

  • Related to Bug #3974: Unsafe casts in ndn::nfd::*::wireDecode() added
Actions #6

Updated by Junxiao Shi over 7 years ago

  • Status changed from New to Closed

The offending test cases are deleted in ndn-cxx:commit:e6835fe12b92b635a89fa641c2294647d5941af9

Actions

Also available in: Atom PDF