From 96e660a789383e3f1209d00295be93e2d7d9a3d5 Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Sat, 31 Jan 2015 21:52:01 -0600 Subject: [PATCH] Fix NULL pointer in `pdal translate --polygon` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The crop_stage was being initialized to a (zero literal) NULL pointer, and was never updated to a real Stage *. This led to a segfault when trying to crop to a polygon with `pdal translate` (and probably would cause segfaults in other situations as well). Rather than creating a StageFactory in a third place in the same method, I just made a method-wide stage factory — losing possible efficiency in favor of simplicity. This patch does not include any unit tests, since AFICT there aren't any unit tests for kernels. --- kernels/translate/TranslateKernel.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/kernels/translate/TranslateKernel.cpp b/kernels/translate/TranslateKernel.cpp index 935e4a6588..0eefad842b 100644 --- a/kernels/translate/TranslateKernel.cpp +++ b/kernels/translate/TranslateKernel.cpp @@ -191,14 +191,15 @@ std::unique_ptr TranslateKernel::makeReader(Options readerOptions) Stage* TranslateKernel::makeTranslate(Options translateOptions, Stage* reader_stage) { + StageFactory f; Stage* final_stage = reader_stage; Options readerOptions = reader_stage->getOptions(); std::map extra_opts = getExtraStageOptions(); if (!m_bounds.empty() || !m_wkt.empty() || !m_output_srs.empty() || extra_opts.size() > 0) { Stage* next_stage = reader_stage; - Stage* crop_stage(0); - Stage* reprojection_stage(0); + Stage* crop_stage = f.createFilter("filters.crop"); + Stage* reprojection_stage = f.createFilter("filters.reprojection"); bool bHaveReprojection = extra_opts.find("filters.reprojection") != extra_opts.end(); @@ -261,7 +262,6 @@ Stage* TranslateKernel::makeTranslate(Options translateOptions, Stage* reader_st if (boost::iequals(m_decimation_method, "VoxelGrid")) { - StageFactory f; Stage* decimation_stage(f.createFilter("filters.pclblock")); Options decimationOptions; @@ -294,7 +294,6 @@ Stage* TranslateKernel::makeTranslate(Options translateOptions, Stage* reader_st decimationOptions.add("step", m_decimation_step); decimationOptions.add("offset", m_decimation_offset); decimationOptions.add("limit", m_decimation_limit); - StageFactory f; Stage* decimation_stage(f.createFilter("filters.decimation")); decimation_stage->setInput(final_stage); decimation_stage->setOptions(decimationOptions);