Fix unsafe std::vector::data() nullptr assumption for empty vectors#95
Draft
Copilot wants to merge 1 commit into
Draft
Fix unsafe std::vector::data() nullptr assumption for empty vectors#95Copilot wants to merge 1 commit into
Copilot wants to merge 1 commit into
Conversation
…ectors When std::vector is empty, data() is not guaranteed to return nullptr. This caused has_times()/has_points()/etc. to incorrectly return true for empty point clouds, since those methods check pointer nullness. Fix by using `vec.empty() ? nullptr : vec.data()` pattern everywhere a storage vector's data pointer is assigned to a raw pointer field. Agent-Logs-Url: https://github.com/koide3/gtsam_points/sessions/12ae22c6-f3d9-4719-8f59-c70496ba892d Co-authored-by: koide3 <31344317+koide3@users.noreply.github.com>
koide3
approved these changes
May 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
std::vector::data()is not guaranteed to returnnullptrwhen empty. ThePointCloudbase class uses raw pointer nullness to signal attribute absence (has_times(),has_points(), etc.), butPointCloudCPUassignsstorage.data()unconditionally — so empty vectors can produce non-null pointers, causinghas_*()to returntruewith no actual data.Fix: Replace all
ptr = storage.data()withptr = storage.empty() ? nullptr : storage.data().point_cloud_cpu.cpp—add_times/points/normals/covs/intensities,clone(),load(), aux_attributespoint_cloud_cpu_funcs.cpp—sample(),voxelgrid_sampling(), aux_attributesgaussian_voxelmap_cpu_funcs.cpp—merge_frames()point_cloud_gpu.cu—download_points()point_cloud_cpu.hpp—add_aux_attribute()templateintensity_gradients.cpp— inline normal/cov estimationincremental_voxelmap_impl.hpp— points assignment