Worth to look at: possible bugs?

Just screening Panda3D source I bumped into unreachable statements, dunno if serious (or what issue could be hidden…) but here they are :

codepanda/src/putil/bamCache.cxx(385): statement is unreachable
    check_cache_size();

panda\src\downloader\chunkedStreamBuf.cxx(226): statement is unreachable
    return 0;

panda\src\pipeline\threadSimpleImpl.I(41): statement is unreachable
    return true;

panda\src\nativenet\socket_tcp_ssl.h(314): statement is unreachable
      es=CRYPTO_thread_id();


panda/src/gobj/shader.cxx(1186): statement is unreachable
    cp_report_error(p, "unrecognized parameter name");


panda/src/pgraph/shaderAttrib.cxx(630): statement is unreachable
    return resfail;

Similarly, some harmless bunch of pointless comparison of unsigned integer with zero : any time (PyLong_AsUnsignedLong(param1_uint)) < 0 is tested

libexpress_igate.cxx(18701): warning #186: pointless comparison of unsigned integer with zero
if ((PyLong_AsUnsignedLong(param1_uint)) < 0 || (PyLong_AsUnsignedLong(param1_uint)) >= ((const ConstPointerToArray< int >*)local_this)->size()) {

libexpress_igate.cxx(19520): warning #186: pointless comparison of unsigned integer with zero
if ((PyLong_AsUnsignedLong(param1_uint)) < 0 || (PyLong_AsUnsignedLong(param1_uint)) >= ((const ConstPointerToArray< unsigned char >*)local_this)->size()) {
^

libexpress_igate.cxx(42209): warning #186: pointless comparison of unsigned integer with zero
if ((PyLong_AsUnsignedLong(param1_uint)) < 0 || (PyLong_AsUnsignedLong(param1_uint)) >= ((const PointerToArray< float >*)local_this)->size()) {
^
libexpress_igate.cxx(42274): warning #186: pointless comparison of unsigned integer with zero
if ((PyLong_AsUnsignedLong(param1_uint)) < 0 || (PyLong_AsUnsignedLong(param1_uint)) >= (local_this)->size()) {

… and so on for this one

and a bunch of totally harmless but pointless comparisons such as:
panda/src/nativenet/buffered_datagramconnection.h(43): pointless comparison of unsigned integer with zero
if(_active_index >= the_size || _active_index < 0)

This is just the normal set of warnings you get whenever you start using a different compiler. I’ve looked over all of them, and they appear to be harmless; we can rework some of them to reduce the error messages. But there are limitations. For instance, when you have code like this:

int foo() {
  while (true) {
    if (x) {
      return 0;
    }
  }

  // can't get here!
  return 1;
}

Some compilers give a warning if you don’t put a return statement at the end of the function (because the function must return a value), while other compilers (like this one) give a warning if you do put a return statement there (because that statement will never be reached). So without using compiler-specific #pragma statements to disable warnings in-code, there’s no way we can write this code to eliminate all warnings.

The warnings in the _igate.cxx files are referring to code generated by interrogate, which didn’t realize that it was constructing a comparison of an unsigned int to zero. We could make that code a little smarter to remove this warning, but it’s not a high priority. (Presumably the compiler will correctly eliminate the pointless comparison.)

David