Skip to content

fix: connect_parts zeros M*C entries in P*C objects buffer - #187

Open
andrewwhitecdw wants to merge 1 commit into
NVIDIA-AI-IOT:masterfrom
andrewwhitecdw:bugfix/connect-parts-connect-parts-zeros-m-c-entries-in-p-c
Open

fix: connect_parts zeros M*C entries in P*C objects buffer#187
andrewwhitecdw wants to merge 1 commit into
NVIDIA-AI-IOT:masterfrom
andrewwhitecdw:bugfix/connect-parts-connect-parts-zeros-m-c-entries-in-p-c

Conversation

@andrewwhitecdw

Copy link
Copy Markdown

This PR addresses the following issue in trt_pose/parse/connect_parts.cpp: connect_parts zeros MC entries in PC objects buffer.

Changes

  • trt_pose/parse/connect_parts.cpp: connect_parts zeros MC entries in PC objects buffer.

Details

--- a/trt_pose/parse/connect_parts.cpp
+++ b/trt_pose/parse/connect_parts.cpp
@@ -1,4 +1,4 @@
-  // initialize objects
-  for (int i = 0; i < C * M; i++) {
-    objects[i] = -1;
-  }
+  // initialize objects
+  for (int i = 0; i < P * C; i++) {
+    objects[i] = -1;
+  }

Tests

  • tests/test_connect_parts.cpp
--- /dev/null
+++ b/tests/test_connect_parts.cpp
@@ -0,0 +1,35 @@
+#include "connect_parts.hpp"
+#include <cassert>
+#include <cstddef>
+#include <cstdint>
+
+using namespace trt_pose::parse;
+
+int main() {
+  // Use M > P so the old C*M initialization would overrun the objects buffer.
+  const int K = 0;
+  const int C = 4;
+  const int M = 10;
+  const int P = 3;
+
+  int object_counts = -1;
+  int objects[P * C + 2];
+  int connections[1];
+  int topology[1];
+  int counts[C] = {0, 0, 0, 0};
+  int workspace[C * M];
+
+  // Place sentinel values past the end of the P*C objects buffer.
+  objects[P * C + 0] = 0xDEADBEEF;
+  objects[P * C + 1] = 0xCAFEBABE;
+
+  connect_parts_out(&object_counts, objects, connections, topology, counts,
+                    K, C, M, P, workspace);
+
+  assert(object_counts == 0);
+  assert(objects[P * C + 0] == 0xDEADBEEF);
+  assert(objects[P * C + 1] == 0xCAFEBABE);
+
+  return 0;
+}

Signed-off-by: andrewwhitecdw <andrewwhitecdw@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant