emcrisostomo / fswatch

A cross-platform file change monitor with multiple backends: Apple OS X File System Events, *BSD kqueue, Solaris/Illumos File Events Notification, Linux inotify, Microsoft Windows and a stat()-based backend.
https://emcrisostomo.github.io/fswatch/
GNU General Public License v3.0
5.06k stars 330 forks source link

redundand check for null on result of static_cast #195

Closed mugiseyebrows closed 6 years ago

mugiseyebrows commented 6 years ago

I believe static_cast cannot return null if argument is not null, check is redundand and exception will never be thrown (assuming clientCallBackInfo is not null, which can be checked less confusing way) https://github.com/emcrisostomo/fswatch/blob/91e529e0e217797ec3606f9f068c6f9f2ad1c279/libfswatch/src/libfswatch/c%2B%2B/fsevents_monitor.cpp#L196-L202

emcrisostomo commented 6 years ago

I think you're confusing static_casting a nullptr versus static_casting an uninitialized pointer. Actually, static_cast maps nullptr to nullptr, so the check is correct. This is mentioned in the standard:

"The null pointer value (4.10) is converted to the null pointer value of the destination type." (5.2.9-8)