openframeworks / openFrameworks

openFrameworks is a community-developed cross platform toolkit for creative coding in C++.
http://openframeworks.cc
Other
9.98k stars 2.55k forks source link

ofColor undefined behavior #8166

Open dimitre opened 3 weeks ago

dimitre commented 3 weeks ago

today I was analyzing code in XCode with address sanitizer on, undefined behavior sanitizer and it indicates an UB on ofColor

Screenshot 2024-10-31 at 00 03 17
ofColor.cpp:172:7: runtime error: 2.14748e+09 is outside the range of representable values of type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ofColor.cpp:172:7 in 
ofColor.cpp:173:7: runtime error: 2.14748e+09 is outside the range of representable values of type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ofColor.cpp:173:7 in 
ofColor.cpp:174:7: runtime error: 2.14748e+09 is outside the range of representable values of type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ofColor.cpp:174:7 in 
ofColor.cpp:175:7: runtime error: 2.14748e+09 is outside the range of representable values of type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ofColor.cpp:175:7 in 
ofColor.cpp:172:7: runtime error: 4.29497e+09 is outside the range of representable values of type 'unsigned int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ofColor.cpp:172:7 in 
ofColor.cpp:173:7: runtime error: 4.29497e+09 is outside the range of representable values of type 'unsigned int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ofColor.cpp:173:7 in 
ofColor.cpp:174:7: runtime error: 4.29497e+09 is outside the range of representable values of type 'unsigned int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ofColor.cpp:174:7 in 
ofColor.cpp:175:7: runtime error: 4.29497e+09 is outside the range of representable values of type 'unsigned int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ofColor.cpp:175:7 in 
ofColor.cpp:172:7: runtime error: 9.22337e+18 is outside the range of representable values of type 'long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ofColor.cpp:172:7 in 
ofColor.cpp:173:7: runtime error: 9.22337e+18 is outside the range of representable values of type 'long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ofColor.cpp:173:7 in 
ofColor.cpp:174:7: runtime error: 9.22337e+18 is outside the range of representable values of type 'long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ofColor.cpp:174:7 in 
ofColor.cpp:175:7: runtime error: 9.22337e+18 is outside the range of representable values of type 'long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ofColor.cpp:175:7 in 
ofColor.cpp:172:7: runtime error: 1.84467e+19 is outside the range of representable values of type 'unsigned long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ofColor.cpp:172:7 in 
ofColor.cpp:173:7: runtime error: 1.84467e+19 is outside the range of representable values of type 'unsigned long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ofColor.cpp:173:7 in 
ofColor.cpp:174:7: runtime error: 1.84467e+19 is outside the range of representable values of type 'unsigned long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ofColor.cpp:174:7 in 
ofColor.cpp:175:7: runtime error: 1.84467e+19 is outside the range of representable values of type 'unsigned long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ofColor.cpp:175:7 in 
setFbo 

and another one in ofGLProgrammableRenderer::draw

Screenshot 2024-10-31 at 00 05 59
roymacdonald commented 3 weeks ago

not sure why the ofColor_ constructor takes floats instead of PixelType. I would assume it is because of that.

dimitre commented 3 weeks ago

@roymacdonald I thought the same. @NickHardeman any downside of using PixelType as the template parameter?

NickHardeman commented 2 weeks ago

@dimitre I can't think of any.... Not sure about the programmable renderer, all of those values in the if statement are bools