Anonymous | Login | 2022-05-25 10:18 UTC | ![]() |
My View | View Issues | Change Log | Roadmap |
View Issue Details [ Jump to Notes ] | [ Issue History ] [ Print ] | ||||||||
ID | Project | Category | View Status | Date Submitted | Last Update | ||||
0000633 | OMNeT++ | simulation kernel | public | 2013-03-06 09:37 | 2017-02-01 15:36 | ||||
Reporter | Harti | ||||||||
Assigned To | andras | ||||||||
Priority | normal | Severity | trivial | Reproducibility | always | ||||
Status | resolved | Resolution | fixed | ||||||
Platform | OS | OS Version | |||||||
Product Version | 4.2.2 | ||||||||
Target Version | Fixed in Version | 5.1pre3 | |||||||
Summary | 0000633: left shift of negative numbers invokes undefined behaviour in C++ | ||||||||
Description | It is undefined behavior in C++ and C to left-shift negative integers. The actual C standard has this in section 6.5.7 paragraph 4 in C++ this is in 5.8 paragraph 3. It is also in the older standards but I don't have the reference at hand. The problem is with the definitions of FSM_Transient and FSM_Exit and can be seen in the samples/routing/nodeBurstApp.cc. FSM_Transient and FSM_Exit are #define FSM_Transient(state) (-(state)) #define FSM_Exit(state) (((state)<<1)|1) So the enum member declaration SEND = FSM_Transient(1) and the case: case FSM_Exit(SEND) expand to case ((-1 << 1) | 1): which invokes undefined behaviour. The fix is to modify FSM_Exit to #define FSM_Exit(state) (((state) * 2) | 1) Given that this is mostly calculated at compile time there is no runtime difference and even the runtime calculation would probably converted to a shift by the compiler. | ||||||||
Tags | No tags attached. | ||||||||
Attached Files | |||||||||
![]() |
|
(0000795) Harti (reporter) 2013-03-06 09:39 |
FSM_Enter should also be modified #define FSM_Enter(state) ((state) * 2) |
(0001295) andras (administrator) 2017-02-01 15:36 |
Agreed, code will use *2 instead of <<1, to avoid undefined behavior. |
![]() |
|||
Date Modified | Username | Field | Change |
2013-03-06 09:37 | Harti | New Issue | |
2013-03-06 09:39 | Harti | Note Added: 0000795 | |
2017-02-01 15:36 | andras | Note Added: 0001295 | |
2017-02-01 15:36 | andras | Status | new => resolved |
2017-02-01 15:36 | andras | Fixed in Version | => 5.1pre3 |
2017-02-01 15:36 | andras | Resolution | open => fixed |
2017-02-01 15:36 | andras | Assigned To | => andras |
Copyright © 2000 - 2022 MantisBT Team |