Project

General

Profile

Actions

Bug #3497

closed

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

Added by Davide Pesavento about 8 years ago. Updated almost 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

Also available in: Atom PDF