Kaynağa Gözat

Fix assorted issues uncovered by clang-tidy

rdb 2 yıl önce
ebeveyn
işleme
aaabb6a652

+ 3 - 2
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;
 }
 
 /**

+ 1 - 1
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();
 

+ 1 - 1
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;
 }
 

+ 0 - 2
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.

+ 1 - 1
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;
 }
 

+ 10 - 9
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);
 }
 
 /**

+ 1 - 1
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;

+ 4 - 4
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);