From 3d7c2505e9a9e0c3500e71070f905abe57179492 Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 11 Feb 2023 15:21:16 +0100 Subject: [PATCH 1/5] pnmimagetypes: Fix memory leaks writing TIFF files --- panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx b/panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx index 3c4634055d..6924816587 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx @@ -1076,7 +1076,7 @@ write_data(xel *array, xelval *alpha) { break; } - buf = (unsigned char*) malloc( bytesperrow ); + buf = (unsigned char*) alloca( bytesperrow ); if ( buf == nullptr ) { pnmimage_tiff_cat.error() << "Can't allocate memory for row buffer\n"; @@ -1147,6 +1147,9 @@ write_data(xel *array, xelval *alpha) { pnmimage_tiff_cat.error() << "Internal error: color not found?!? row=" << row << " col=" << col << "\n"; + if (cht != nullptr) { + ppm_freecolorhash(cht); + } return 0; } *tP++ = (unsigned char) s; @@ -1190,6 +1193,10 @@ write_data(xel *array, xelval *alpha) { TIFFFlushData( tif ); TIFFClose( tif ); + if (cht != nullptr) { + ppm_freecolorhash(cht); + } + return _y_size; } From 173dd67b5221e82afbebf2f1254ff27f419bb9d9 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 12 Feb 2023 13:07:14 +0100 Subject: [PATCH 2/5] glgsg: Fix p3d_LightModel.ambient not updating properly --- panda/src/glstuff/glShaderContext_src.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/panda/src/glstuff/glShaderContext_src.cxx b/panda/src/glstuff/glShaderContext_src.cxx index 34d6c1a706..aa6af13edf 100644 --- a/panda/src/glstuff/glShaderContext_src.cxx +++ b/panda/src/glstuff/glShaderContext_src.cxx @@ -1293,7 +1293,7 @@ reflect_uniform(int i, char *name_buffer, GLsizei name_buflen) { bind._func = Shader::SMF_first; bind._part[0] = Shader::SMO_light_ambient; bind._arg[0] = nullptr; - bind._dep[0] = Shader::SSD_general | Shader::SSD_light; + bind._dep[0] = Shader::SSD_general | Shader::SSD_light | Shader::SSD_frame; bind._part[1] = Shader::SMO_identity; bind._arg[1] = nullptr; bind._dep[1] = Shader::SSD_NONE; From a9e9cfae1c3147d581bc99234b09b88a33324bfd Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 12 Feb 2023 13:22:16 +0100 Subject: [PATCH 3/5] py_panda: Fix definition of _PyErr_OCCURRED for Python >3.12.0a5 It should not be redefined for Python versions after 3.3.3, and if it's not defined by Python, it should just map to PyErr_Occurred() See also #1457 --- dtool/src/interrogatedb/py_compat.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dtool/src/interrogatedb/py_compat.h b/dtool/src/interrogatedb/py_compat.h index 35edfdec5a..c5474b21ee 100644 --- a/dtool/src/interrogatedb/py_compat.h +++ b/dtool/src/interrogatedb/py_compat.h @@ -127,8 +127,10 @@ typedef long Py_hash_t; #if PY_MAJOR_VERSION >= 3 // Python 3 versions before 3.3.3 defined this incorrectly. -# undef _PyErr_OCCURRED -# define _PyErr_OCCURRED() (PyThreadState_GET()->curexc_type) +# if PY_VERSION_HEX < 0x03030300 +# undef _PyErr_OCCURRED +# define _PyErr_OCCURRED() (PyThreadState_GET()->curexc_type) +# endif // Python versions before 3.3 did not define this. # if PY_VERSION_HEX < 0x03030000 From 914993f31b9a5208b5b2fbfa38c22c5c5b0ef13d Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 12 Feb 2023 13:49:44 +0100 Subject: [PATCH 4/5] putil: Fix SimpleHashMap error reporting at static init time --- panda/src/putil/simpleHashMap.I | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/panda/src/putil/simpleHashMap.I b/panda/src/putil/simpleHashMap.I index 62809b4ffe..4f322faa86 100644 --- a/panda/src/putil/simpleHashMap.I +++ b/panda/src/putil/simpleHashMap.I @@ -532,11 +532,10 @@ validate() const { size_t index = (size_t)index_array[slot]; ++count; if (index >= _num_entries) { - util_cat.error() + write(util_cat->error() << "SimpleHashMap " << this << " is invalid: slot " << slot << " contains index " << index << " which is past the end of the" - " table\n"; - write(util_cat.error(false)); + " table\n"); return false; } nassertd(index < _num_entries) continue; @@ -546,21 +545,19 @@ validate() const { wants_slot = next_hash(wants_slot); } if (wants_slot != slot) { - util_cat.error() + write(util_cat->error() << "SimpleHashMap " << this << " is invalid: key " << _table[index]._key << " should be in slot " << wants_slot - << " instead of " << slot << " (ideal is " << ideal_slot << ")\n"; - write(util_cat.error(false)); + << " instead of " << slot << " (ideal is " << ideal_slot << ")\n"); return false; } } } if (count != _num_entries) { - util_cat.error() + write(util_cat->error() << "SimpleHashMap " << this << " is invalid: reports " << _num_entries - << " entries, actually has " << count << "\n"; - write(util_cat.error(false)); + << " entries, actually has " << count << "\n"); return false; } From aaabb6a65280650a83616c52a205efc33419e155 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 12 Feb 2023 13:55:59 +0100 Subject: [PATCH 5/5] Fix assorted issues uncovered by clang-tidy --- contrib/src/ai/aiWorld.cxx | 5 +++-- dtool/src/cppparser/cppInstance.cxx | 2 +- dtool/src/prc/encryptStreamBuf.cxx | 2 +- panda/src/express/multifile.cxx | 2 -- panda/src/express/zStreamBuf.cxx | 2 +- panda/src/gobj/geomVertexArrayFormat.cxx | 19 ++++++++++--------- panda/src/pgraph/cullTraverserData.h | 2 +- panda/src/pnmimage/pnmimage_base.cxx | 8 ++++---- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/contrib/src/ai/aiWorld.cxx b/contrib/src/ai/aiWorld.cxx index bbdf894e13..074a93ac69 100644 --- a/contrib/src/ai/aiWorld.cxx +++ b/contrib/src/ai/aiWorld.cxx @@ -99,8 +99,9 @@ Flock AIWorld::get_flock(unsigned int flock_id) { return *_flock_pool[i]; } } - Flock *null_flock = nullptr; - return *null_flock; + static Flock null_flock(0, 0.0, 0.0, 0, 0, 0); + nassertr(false, null_flock); + return null_flock; } /** diff --git a/dtool/src/cppparser/cppInstance.cxx b/dtool/src/cppparser/cppInstance.cxx index 3bb3bb725a..8f40a5735b 100644 --- a/dtool/src/cppparser/cppInstance.cxx +++ b/dtool/src/cppparser/cppInstance.cxx @@ -351,7 +351,7 @@ check_for_constructor(CPPScope *current_scope, CPPScope *global_scope) { } CPPFunctionType *func = _type->as_function_type(); - if (func != nullptr) { + if (func != nullptr && scope != nullptr) { string method_name = get_local_name(scope); string class_name = scope->get_local_name(); diff --git a/dtool/src/prc/encryptStreamBuf.cxx b/dtool/src/prc/encryptStreamBuf.cxx index afe8ec1d61..def104c904 100644 --- a/dtool/src/prc/encryptStreamBuf.cxx +++ b/dtool/src/prc/encryptStreamBuf.cxx @@ -433,9 +433,9 @@ sync() { size_t n = pptr() - pbase(); write_chars(pbase(), n); pbump(-(int)n); + _dest->flush(); } - _dest->flush(); return 0; } diff --git a/panda/src/express/multifile.cxx b/panda/src/express/multifile.cxx index 4467132b79..bd17d6bd1f 100644 --- a/panda/src/express/multifile.cxx +++ b/panda/src/express/multifile.cxx @@ -2283,8 +2283,6 @@ read_index() { read_cert_special = true; } else { _subfiles.push_back(subfile); - } - if (!subfile->is_cert_special()) { if (bytes_skipped != 0) { // If the index entries don't follow exactly sequentially (except for // the cert special files), the file ought to be repacked. diff --git a/panda/src/express/zStreamBuf.cxx b/panda/src/express/zStreamBuf.cxx index 57a64bed7a..ee41995f4b 100644 --- a/panda/src/express/zStreamBuf.cxx +++ b/panda/src/express/zStreamBuf.cxx @@ -263,9 +263,9 @@ sync() { size_t n = pptr() - pbase(); write_chars(pbase(), n, Z_SYNC_FLUSH); pbump(-(int)n); + _dest->flush(); } - _dest->flush(); return 0; } diff --git a/panda/src/gobj/geomVertexArrayFormat.cxx b/panda/src/gobj/geomVertexArrayFormat.cxx index 9cb5c41e91..f758d6c13d 100644 --- a/panda/src/gobj/geomVertexArrayFormat.cxx +++ b/panda/src/gobj/geomVertexArrayFormat.cxx @@ -551,8 +551,8 @@ get_format_string(bool pad) const { } // Synthesize the format string. - char *fmt = (char*) malloc(row_size + 1); - memset((void*) fmt, 0, row_size + 1); + char *fmt = (char *)alloca(row_size + 1); + memset((void *)fmt, 0, row_size + 1); int fi = 0; int offset = 0; @@ -566,6 +566,7 @@ get_format_string(bool pad) const { } char fmt_code = 'x'; + int num_components = column->get_num_components(); switch (column->get_numeric_type()) { case NT_uint8: fmt_code = 'B'; @@ -578,6 +579,7 @@ get_format_string(bool pad) const { case NT_uint32: case NT_packed_dcba: case NT_packed_dabc: + case NT_packed_ufloat: fmt_code = 'I'; break; @@ -604,22 +606,21 @@ get_format_string(bool pad) const { default: gobj_cat.error() << "Unknown numeric type " << column->get_numeric_type() << "!\n"; - return nullptr; + num_components *= column->get_component_bytes(); } - memset((void*) (fmt + fi), fmt_code, column->get_num_components()); + memset((void*) (fmt + fi), fmt_code, num_components); offset += column->get_total_bytes(); - fi += column->get_num_components(); + fi += num_components; } if (offset < row_size) { // Add padding bytes. int pad = row_size - offset; - memset((void*) (fmt + fi), 'x', pad); + memset((void *)(fmt + fi), 'x', pad); + ++fi; } - std::string fmt_string (fmt); - free(fmt); - return fmt_string; + return std::string(fmt, (size_t)fi); } /** diff --git a/panda/src/pgraph/cullTraverserData.h b/panda/src/pgraph/cullTraverserData.h index eca5f142dc..4e47a02267 100644 --- a/panda/src/pgraph/cullTraverserData.h +++ b/panda/src/pgraph/cullTraverserData.h @@ -73,7 +73,7 @@ private: // We store a chain leading all the way to the root, so that we can compose // a NodePath. We may be able to eliminate this requirement in the future. const CullTraverserData *_next; - NodePathComponent *_start; + NodePathComponent *_start; // NOLINT(*.UninitializedObject) public: PandaNodePipelineReader _node_reader; diff --git a/panda/src/pnmimage/pnmimage_base.cxx b/panda/src/pnmimage/pnmimage_base.cxx index d5ef09e415..e1290f27bb 100644 --- a/panda/src/pnmimage/pnmimage_base.cxx +++ b/panda/src/pnmimage/pnmimage_base.cxx @@ -39,11 +39,11 @@ pm_message(const char *format, ...) { #else vsnprintf(buffer, buffer_size, format, ap); #endif + va_end(ap); + nassertv(strlen(buffer) < buffer_size); pnmimage_cat.info() << buffer << "\n"; - - va_end(ap); } /** @@ -63,12 +63,12 @@ pm_error(const char *format, ...) { #else vsnprintf(buffer, buffer_size, format, ap); #endif + va_end(ap); + nassertv(strlen(buffer) < buffer_size); pnmimage_cat.error() << buffer << "\n"; - va_end(ap); - // Now we're supposed to exit. Inconvenient if we were running Panda // interactively, but that's the way it is. exit(1);