fritzing / fritzing-app

Fritzing desktop application
http://fritzing.org
Other
3.97k stars 826 forks source link

Fix undefined behaviours / runtime errors #4016

Closed feliwir closed 8 months ago

feliwir commented 1 year ago

Current Behaviour

I was running Fritzing compiled with UBSan (undefined behaviour sanitizer) and there are a couple places where the app reads from uninitialized variables (and uses those):

  1. https://github.com/fritzing/fritzing-app/blob/develop/src/infoview/htmlinfoview.cpp#L731: The varible m_lastPropsSwappingEnabled does never get initialized or set at all - making the check for it undefined
  2. https://github.com/fritzing/fritzing-app/blob/develop/src/items/itembase.cpp#L352: The variable m_viewLayerID gets retrieved but is not initialized - making the content of it undefined
  3. https://github.com/fritzing/fritzing-app/blob/develop/src/autoroute/panelizer.cpp#L1043: In this line (and all w*h multiplications below) a signed integer overflow occurs (e.g. 612625 * 199763) - making this undefined

This list is probably not complete yet - i need to check the entire functionality

Build: Latest / Any

Operating System: Linux 64-bit

Steps to reproduce: Compile with UBSan

Expected Behaviour

No undefined behaviour at runtime. If i know what the sensible default values should be i can do a PR

KjellMorgenstern commented 9 months ago

Partially solved for 1.0.2 : I used memcheck to point me to initialized uninitialized variables created on the heap.