OMNeT++/OMNEST Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0000633OMNeT++simulation kernelpublic2013-03-06 09:372017-02-01 15:36
ReporterHarti 
Assigned Toandras 
PrioritynormalSeveritytrivialReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version4.2.2 
Target VersionFixed in Version5.1pre3 
Summary0000633: left shift of negative numbers invokes undefined behaviour in C++
DescriptionIt 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.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(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.

- Issue History
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 - 2019 MantisBT Team
Powered by Mantis Bugtracker