diff --git a/PotreeConverter/.vscode/keybindings.json b/PotreeConverter/.vscode/keybindings.json new file mode 100644 index 0000000..20a7335 --- /dev/null +++ b/PotreeConverter/.vscode/keybindings.json @@ -0,0 +1,20 @@ +// Place your key bindings in this file to overwrite the defaults +[ + { + "key": "ctrl+l", + "command": "editor.action.deleteLines", + "when": "editorTextFocus && !editorReadonly" + },{ + "key": "ctrl+shift+i", + "command": "editor.action.toggleRenderWhitespace" + },{ + "key": "ctrl+d", + "command": "editor.action.copyLinesDownAction" + },{ + "key": "alt+2", + "command": "type", + "args": { + "text": "`" + } + } +] \ No newline at end of file diff --git a/PotreeConverter/.vscode/launch.json b/PotreeConverter/.vscode/launch.json new file mode 100644 index 0000000..dc7829b --- /dev/null +++ b/PotreeConverter/.vscode/launch.json @@ -0,0 +1,113 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(Windows) Launch", + "type": "cppvsdbg", + "request": "launch", + "program": "${workspaceFolder}/build/Release/PotreeConverter.exe", + "args": [ + + + + + // =================== + // SYSTEM 1 + // =================== + // "D:/dev/pointclouds/bunny_20M.las", + // "D:/dev/pointclouds/mschuetz/lion.las", + // "D:/dev/pointclouds/riegl/retz.laz", + // "D:/dev/pointclouds/pix4d/eclepens.las", + // "D:/dev/pointclouds/pix4d/matterhorn.laz", + // "D:/dev/pointclouds/archpro/heidentor.las", + // "D:/dev/pointclouds/hg_v2_clip.las", + // "D:/dev/pointclouds/CA13", + + // "D:/dev/pointclouds/CA13/ot_35120D8108C_1.laz", + // "D:/dev/pointclouds/CA13/ot_35120D8108D_1.laz", + // "D:/dev/pointclouds/CA13/ot_35120D8109A_1.laz", + // "D:/dev/pointclouds/CA13/ot_35120D8109B_1.laz", + // "D:/dev/pointclouds/CA13/ot_35120D8109C_1.laz", + // "D:/dev/pointclouds/CA13/ot_35120D8109D_1.laz", + + // "D:/temp/crashreport2/cube.laz", + // "D:/temp/crashreport2/trott_crashing", + // "D:/temp/crashreport/3dbuildings_walls_azimuth.laz", + // "-o", "D:/temp/crashreport2/converted", + + // "D:/dev/pointclouds/CA13/ot_35120B4122C_1.laz", + // "D:/dev/pointclouds/CA13/ot_35120B4121D_1.laz", + // "D:/dev/pointclouds/CA13/ot_35120B4301B_1.laz", + // "D:/dev/pointclouds/CA13/ot_35120B4301D_1.laz", + // "D:/dev/pointclouds/CA13/ot_35120B4302C_1.laz", + // "D:/dev/pointclouds/CA13/ot_35120B4302B_1.laz", + // "D:/dev/pointclouds/CA13/ot_35120B4122D_1.laz", + // "D:/dev/pointclouds/CA13/ot_35120B4302D_1.laz", + // "D:/dev/pointclouds/CA13/ot_35120B4302A_1.laz", + + // "D:/temp/C_25ez1.laz", + + // "F:/pointclouds/AHN3/files/C_25ez1.laz", + // "F:/pointclouds/AHN3/files/C_25gn1.laz", + // "F:/pointclouds/AHN3/files/C_25bz1.laz", + // "F:/pointclouds/AHN3/files/C_25bz2.laz", + // "F:/pointclouds/AHN3/files/C_25ez2.laz", + // "F:/pointclouds/AHN3/files/C_25dn1.laz", + // "F:/pointclouds/AHN3/files/C_25dn2.laz", + // "F:/pointclouds/AHN3/files/C_25gn2.laz", + + // "D:/temp/compression/C_05DN2.LAZ", + + // "D:/dev/pointclouds/tuwien_baugeschichte/candi Banyunibo", + + + "D:/dev/pointclouds/sitn/potree2/aerial_lidar2019_2524_1197_laz14_dip.laz", + // "D:/dev/pointclouds/sitn/potree2/aerial_lidar2019_2524_1197_las14.las", + + // "D:/temp/Bargello10Mtest.las", + + + // "D:/dev/pointclouds/testdata/Bargello10Mtest.las", + // "D:/dev/pointclouds/testdata/crash.las", + // "D:/dev/pointclouds/testdata/eclepens.laz", + // "D:/dev/pointclouds/testdata/Grab15.laz", + // "D:/dev/pointclouds/testdata/heidentor.las", + // "D:/dev/pointclouds/testdata/lion.laz", + // "D:/dev/pointclouds/testdata/3dbuildings_walls_azimuth.laz", + + + "-o", "D:/temp/cpotree/sitn_dip_2.0", + + // =================== + // SYSTEM 2 + // =================== + // "C:/dev/pointclouds/nvidia.las", + // "C:/dev/pointclouds/eclepens.las", + // "-o", "C:/temp/test/converter", + + // =================== + // OPTIONS + // =================== + // "--flags", "just-stats", + // "--flags", "no-chunking", + // "--flags", "no-indexing", "keep-chunks", + // "--flags", "no-chunking", "keep-chunks", + // "--flags", "keep-chunks", + // "--keep-chunks", + // "--generate-page", "heidentor", + // "-m", "poisson", // ["poisson", "poisson_average", "random"] + // "--chunkMethod", "SKIP" // [LASZIP, LAS_CUSTOM, SKIP] + // "--attributes", "rgb", "Dip (degrees)", "Dip direction (degrees)", "NormalX", "NormalY", "NormalZ", + // "--attributes" , "rgb", "intensity", "classification", "mjpmie", + "--encoding", "BROTLI", + ], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false + } + ] +} \ No newline at end of file diff --git a/PotreeConverter/.vscode/settings.json b/PotreeConverter/.vscode/settings.json new file mode 100644 index 0000000..a291fa5 --- /dev/null +++ b/PotreeConverter/.vscode/settings.json @@ -0,0 +1,106 @@ +{ + "workbench.editor.enablePreview": false, + "files.associations": { + "*.cs": "cpp", + "*.wgsl": "cpp", + "*.vs": "cpp", + "*.fs": "cpp", + "filesystem": "cpp", + "xstring": "cpp", + "algorithm": "cpp", + "array": "cpp", + "atomic": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "concepts": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "deque": "cpp", + "exception": "cpp", + "execution": "cpp", + "resumable": "cpp", + "forward_list": "cpp", + "fstream": "cpp", + "functional": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "iterator": "cpp", + "limits": "cpp", + "list": "cpp", + "locale": "cpp", + "map": "cpp", + "memory": "cpp", + "mutex": "cpp", + "new": "cpp", + "numeric": "cpp", + "ostream": "cpp", + "queue": "cpp", + "ratio": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "string": "cpp", + "system_error": "cpp", + "thread": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "typeinfo": "cpp", + "unordered_map": "cpp", + "utility": "cpp", + "valarray": "cpp", + "vector": "cpp", + "xfacet": "cpp", + "xhash": "cpp", + "xiosbase": "cpp", + "xlocale": "cpp", + "xlocbuf": "cpp", + "xlocinfo": "cpp", + "xlocmes": "cpp", + "xlocmon": "cpp", + "xlocnum": "cpp", + "xloctime": "cpp", + "xmemory": "cpp", + "xstddef": "cpp", + "xtr1common": "cpp", + "xtree": "cpp", + "xutility": "cpp", + "random": "cpp", + "hash_map": "cpp", + "set": "cpp", + "condition_variable": "cpp", + "regex": "cpp", + "stack": "cpp", + "variant": "cpp", + "bit": "cpp", + "charconv": "cpp", + "compare": "cpp", + "format": "cpp", + "optional": "cpp", + "stop_token": "cpp" + }, + "files.trimTrailingWhitespace": false, + "editor.fontSize": 28, + "editor.autoIndent": "advanced", + "editor.detectIndentation": false, + "editor.insertSpaces": false, + "editor.minimap.enabled": false, + "editor.autoClosingBrackets": "never", + "editor.formatOnType": false, + "editor.acceptSuggestionOnEnter": "off", + "editor.acceptSuggestionOnCommitCharacter": false, + "editor.mouseWheelZoom": true, + "editor.renderWhitespace": "all", + "editor.autoClosingQuotes": "never", + "editor.autoSurround": "never", +} \ No newline at end of file diff --git a/PotreeConverter/CMakeLists.txt b/PotreeConverter/CMakeLists.txt index bc60663..a9186e4 100644 --- a/PotreeConverter/CMakeLists.txt +++ b/PotreeConverter/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.16) +cmake_minimum_required(VERSION 2.) set(CMAKE_SUPPRESS_REGENERATION true) project(PotreeConverter LANGUAGES CXX) diff --git a/PotreeConverter/Converter/include/PotreeConverter.h b/PotreeConverter/Converter/include/PotreeConverter.h index 5260056..c175650 100644 --- a/PotreeConverter/Converter/include/PotreeConverter.h +++ b/PotreeConverter/Converter/include/PotreeConverter.h @@ -207,9 +207,13 @@ inline Attributes computeOutputAttributes(vector& sources, vector attributes = computeOutputAttributes(header); diff --git a/PotreeConverter/Converter/include/sampler_poisson.h b/PotreeConverter/Converter/include/sampler_poisson.h index 244a3b6..377e54f 100644 --- a/PotreeConverter/Converter/include/sampler_poisson.h +++ b/PotreeConverter/Converter/include/sampler_poisson.h @@ -100,7 +100,15 @@ struct SamplerPoisson : public Sampler { double y = (xyz[1] * scale.y) + offset.y; double z = (xyz[2] * scale.z) + offset.z; - Point point = { x, y, z, i, childIndex }; + #if defined(__APPLE__) + // convert int64_t to int32_t for apple to be happy + int32_t apple_i = i; + int32_t apple_childIndex = childIndex; + + Point point = { x, y, z, apple_i, apple_childIndex }; + #else + Point point = { x, y, z, i, childIndex }; + #endif points.push_back(point); } @@ -179,8 +187,12 @@ struct SamplerPoisson : public Sampler { }; + #if defined(__APPLE__) + std::sort(points.begin(), points.end(), [center](Point a, Point b) -> bool { + #else auto parallel = std::execution::par_unseq; std::sort(parallel, points.begin(), points.end(), [center](Point a, Point b) -> bool { + #endif auto ax = a.x - center.x; auto ay = a.y - center.y; diff --git a/PotreeConverter/Converter/include/sampler_poisson_average.h b/PotreeConverter/Converter/include/sampler_poisson_average.h index 481da4b..3e0f8d6 100644 --- a/PotreeConverter/Converter/include/sampler_poisson_average.h +++ b/PotreeConverter/Converter/include/sampler_poisson_average.h @@ -280,9 +280,14 @@ struct SamplerPoissonAverage : public Sampler { }; + + #if defined(__APPLE__) + std::sort(points.begin(), points.end(), [center](Point a, Point b) -> bool { + #else auto parallel = std::execution::par_unseq; std::sort(parallel, points.begin(), points.end(), [center](Point a, Point b) -> bool { - + #endif + auto ax = a.x - center.x; auto ay = a.y - center.y; auto az = a.z - center.z; diff --git a/PotreeConverter/Converter/libs/laszip/src/lasindex.cpp b/PotreeConverter/Converter/libs/laszip/src/lasindex.cpp index c16bdb4..89b703d 100644 --- a/PotreeConverter/Converter/libs/laszip/src/lasindex.cpp +++ b/PotreeConverter/Converter/libs/laszip/src/lasindex.cpp @@ -469,9 +469,9 @@ BOOL LASindex::append(const char* file_name) const bytestreamout->seek(offset_to_special_evlrs); LASevlr lax_evlr; - sprintf(lax_evlr.user_id, "LAStools"); + snprintf(lax_evlr.user_id, sizeof(lax_evlr.user_id), "LAStools"); lax_evlr.record_id = 30; - sprintf(lax_evlr.description, "LAX spatial indexing (LASindex)"); + snprintf(lax_evlr.description, sizeof(lax_evlr.description), "LAX spatial indexing (LASindex)"); bytestreamout->put16bitsLE((const U8*)&(lax_evlr.reserved)); bytestreamout->putBytes((const U8*)lax_evlr.user_id, 16); diff --git a/PotreeConverter/Converter/libs/laszip/src/lasreadpoint.cpp b/PotreeConverter/Converter/libs/laszip/src/lasreadpoint.cpp index 5a2b812..0f7fbc8 100644 --- a/PotreeConverter/Converter/libs/laszip/src/lasreadpoint.cpp +++ b/PotreeConverter/Converter/libs/laszip/src/lasreadpoint.cpp @@ -508,17 +508,17 @@ BOOL LASreadPoint::read(U8* const * point) // end-of-file if (dec) { - sprintf(last_error, "end-of-file during chunk with index %u", current_chunk); + snprintf(last_error, sizeof(last_error), "end-of-file during chunk with index %u", current_chunk); } else { - sprintf(last_error, "end-of-file"); + snprintf(last_error, sizeof(last_error), "end-of-file"); } } else { // decompression error - sprintf(last_error, "chunk with index %u of %u is corrupt", current_chunk, tabled_chunks); + snprintf(last_error, sizeof(last_error), "chunk with index %u of %u is corrupt", current_chunk, tabled_chunks); // if we know where the next chunk starts ... if ((current_chunk+1) < tabled_chunks) { @@ -550,7 +550,7 @@ BOOL LASreadPoint::check_end() // create error string if (last_error == 0) last_error = new CHAR[128]; // report error - sprintf(last_error, "chunk with index %u of %u is corrupt", current_chunk, tabled_chunks); + snprintf(last_error, sizeof(last_error), "chunk with index %u of %u is corrupt", current_chunk, tabled_chunks); return FALSE; } } @@ -606,7 +606,7 @@ BOOL LASreadPoint::read_chunk_table() // create error string if (last_error == 0) last_error = new CHAR[128]; // report error - sprintf(last_error, "compressor was interrupted before writing adaptive chunk table of LAZ file"); + snprintf(last_error, sizeof(last_error), "compressor was interrupted before writing adaptive chunk table of LAZ file"); return FALSE; } // otherwise we build the chunk table as we read the file @@ -621,7 +621,7 @@ BOOL LASreadPoint::read_chunk_table() // create warning string if (last_warning == 0) last_warning = new CHAR[128]; // report warning - sprintf(last_warning, "compressor was interrupted before writing chunk table of LAZ file"); + snprintf(last_warning, sizeof(last_warning), "compressor was interrupted before writing chunk table of LAZ file"); return TRUE; } @@ -751,21 +751,21 @@ BOOL LASreadPoint::read_chunk_table() // report warning if (last_position == chunk_table_start_position) { - sprintf(last_warning, "chunk table is missing. improper use of LAZ compressor?"); + snprintf(last_warning, sizeof(last_warning), "chunk table is missing. improper use of LAZ compressor?"); } else { #ifdef _WIN32 - sprintf(last_warning, "chunk table and %I64d bytes are missing. LAZ file truncated during copy or transfer?", chunk_table_start_position - last_position); + snprintf(last_warning, sizeof(last_warning), "chunk table and %I64d bytes are missing. LAZ file truncated during copy or transfer?", chunk_table_start_position - last_position); #else - sprintf(last_warning, "chunk table and %lld bytes are missing. LAZ file truncated during copy or transfer?", chunk_table_start_position - last_position); + snprintf(last_warning, sizeof(last_warning), "chunk table and %lld bytes are missing. LAZ file truncated during copy or transfer?", chunk_table_start_position - last_position); #endif } } else { // report warning - sprintf(last_warning, "corrupt chunk table"); + snprintf(last_warning, sizeof(last_warning), "corrupt chunk table"); } } if (!instream->seek(chunks_start)) diff --git a/PotreeConverter/Converter/libs/laszip/src/lasunzipper.cpp b/PotreeConverter/Converter/libs/laszip/src/lasunzipper.cpp index 3519a68..c03eebe 100644 --- a/PotreeConverter/Converter/libs/laszip/src/lasunzipper.cpp +++ b/PotreeConverter/Converter/libs/laszip/src/lasunzipper.cpp @@ -1,12 +1,12 @@ -/* -=============================================================================== - - FILE: lasunzipper.cpp - - CONTENTS: - - see corresponding header file - +/* +=============================================================================== + + FILE: lasunzipper.cpp + + CONTENTS: + + see corresponding header file + PROGRAMMERS: martin.isenburg@rapidlasso.com - http://rapidlasso.com @@ -21,13 +21,13 @@ This software is distributed WITHOUT ANY WARRANTY and without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - - CHANGE HISTORY: - - see corresponding header file - -=============================================================================== -*/ + + CHANGE HISTORY: + + see corresponding header file + +=============================================================================== +*/ #include "lasunzipper.hpp" #include @@ -118,22 +118,22 @@ const char* LASunzipper::get_error() const bool LASunzipper::return_error(const char* error) { char err[256]; - sprintf(err, "%s (LASzip v%d.%dr%d)", error, LASZIP_VERSION_MAJOR, LASZIP_VERSION_MINOR, LASZIP_VERSION_REVISION); + snprintf(err, sizeof(err), "%s (LASzip v%d.%dr%d)", error, LASZIP_VERSION_MAJOR, LASZIP_VERSION_MINOR, LASZIP_VERSION_REVISION); if (error_string) free(error_string); error_string = LASCopyString(err); return false; } -LASunzipper::LASunzipper() -{ +LASunzipper::LASunzipper() +{ error_string = 0; - count = 0; - stream = 0; + count = 0; + stream = 0; reader = 0; -} - -LASunzipper::~LASunzipper() +} + +LASunzipper::~LASunzipper() { if (error_string) free(error_string); - if (reader || stream) close(); -} + if (reader || stream) close(); +} diff --git a/PotreeConverter/Converter/libs/laszip/src/laszip.cpp b/PotreeConverter/Converter/libs/laszip/src/laszip.cpp index 532c3d4..64080f5 100644 --- a/PotreeConverter/Converter/libs/laszip/src/laszip.cpp +++ b/PotreeConverter/Converter/libs/laszip/src/laszip.cpp @@ -196,7 +196,7 @@ bool LASzip::return_error(const char* error) #define CopyString strdup #endif char err[256]; - sprintf(err, "%s (LASzip v%d.%dr%d)", error, LASZIP_VERSION_MAJOR, LASZIP_VERSION_MINOR, LASZIP_VERSION_REVISION); + snprintf(err, sizeof(err), "%s (LASzip v%d.%dr%d)", error, LASZIP_VERSION_MAJOR, LASZIP_VERSION_MINOR, LASZIP_VERSION_REVISION); if (error_string) free(error_string); error_string = CopyString(err); return false; @@ -206,7 +206,7 @@ bool LASzip::check_compressor(const U16 compressor) { if (compressor < LASZIP_COMPRESSOR_TOTAL_NUMBER_OF) return true; char error[64]; - sprintf(error, "compressor %d not supported", compressor); + snprintf(error, sizeof(error), "compressor %d not supported", compressor); return return_error(error); } @@ -214,7 +214,7 @@ bool LASzip::check_coder(const U16 coder) { if (coder < LASZIP_CODER_TOTAL_NUMBER_OF) return true; char error[64]; - sprintf(error, "coder %d not supported", coder); + snprintf(error, sizeof(error), "coder %d not supported", coder); return return_error(error); } @@ -266,7 +266,7 @@ bool LASzip::check_item(const LASitem* item) if (1) { char error[64]; - sprintf(error, "item unknown (%d,%d,%d)", item->type, item->size, item->version); + snprintf(error, sizeof(error), "item unknown (%d,%d,%d)", item->type, item->size, item->version); return return_error(error); } } @@ -287,7 +287,7 @@ bool LASzip::check_items(const U16 num_items, const LASitem* items, const U16 po if (point_size && (point_size != size)) { CHAR temp[66]; - sprintf(temp, "point has size of %d but items only add up to %d bytes", point_size, size); + snprintf(temp, sizeof(temp), "point has size of %d but items only add up to %d bytes", point_size, size); return return_error(temp); } return true; @@ -489,7 +489,7 @@ bool LASzip::setup(U16* num_items, LASitem** items, const U8 point_type, const U if (1) { char error[64]; - sprintf(error, "point type %d unknown", point_type); + snprintf(error, sizeof(error), "point type %d unknown", point_type); return return_error(error); } } diff --git a/PotreeConverter/Converter/libs/laszip/src/laszip_dll.cpp b/PotreeConverter/Converter/libs/laszip/src/laszip_dll.cpp index 36e4f5e..6e5119d 100644 --- a/PotreeConverter/Converter/libs/laszip/src/laszip_dll.cpp +++ b/PotreeConverter/Converter/libs/laszip/src/laszip_dll.cpp @@ -237,7 +237,7 @@ laszip_get_error( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_get_error"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_get_error"); return 1; } @@ -260,7 +260,7 @@ laszip_get_warning( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_get_warning"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_get_warning"); return 1; } @@ -314,13 +314,13 @@ laszip_clean( { if (laszip_dll->reader) { - sprintf(laszip_dll->error, "cannot clean while reader is open."); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot clean while reader is open."); return 1; } if (laszip_dll->writer) { - sprintf(laszip_dll->error, "cannot clean while writer is open."); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot clean while writer is open."); return 1; } @@ -441,7 +441,7 @@ laszip_clean( // create default header - sprintf(laszip_dll->header.generating_software, "LASzip DLL %d.%d r%d (%d)", LASZIP_VERSION_MAJOR, LASZIP_VERSION_MINOR, LASZIP_VERSION_REVISION, LASZIP_VERSION_BUILD_DATE); + snprintf(laszip_dll->header.generating_software, sizeof(laszip_dll->header.generating_software), "LASzip DLL %d.%d r%d (%d)", LASZIP_VERSION_MAJOR, LASZIP_VERSION_MINOR, LASZIP_VERSION_REVISION, LASZIP_VERSION_BUILD_DATE); laszip_dll->header.version_major = 1; laszip_dll->header.version_minor = 2; laszip_dll->header.header_size = 227; @@ -457,7 +457,7 @@ laszip_clean( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_clean"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_clean"); return 1; } @@ -502,7 +502,7 @@ laszip_get_header_pointer( { if (header_pointer == 0) { - sprintf(laszip_dll->error, "laszip_header_struct pointer 'header_pointer' is zero"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "laszip_header_struct pointer 'header_pointer' is zero"); return 1; } @@ -510,7 +510,7 @@ laszip_get_header_pointer( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_get_header_pointer"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_get_header_pointer"); return 1; } @@ -532,7 +532,7 @@ laszip_get_point_pointer( { if (point_pointer == 0) { - sprintf(laszip_dll->error, "laszip_point_struct pointer 'point_pointer' is zero"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "laszip_point_struct pointer 'point_pointer' is zero"); return 1; } @@ -540,7 +540,7 @@ laszip_get_point_pointer( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_get_point_pointer"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_get_point_pointer"); return 1; } @@ -562,13 +562,13 @@ laszip_get_point_count( { if (count == 0) { - sprintf(laszip_dll->error, "laszip_I64 pointer 'count' is zero"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "laszip_I64 pointer 'count' is zero"); return 1; } if ((laszip_dll->reader == 0) && (laszip_dll->writer == 0)) { - sprintf(laszip_dll->error, "getting count before reader or writer was opened"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "getting count before reader or writer was opened"); return 1; } @@ -576,7 +576,7 @@ laszip_get_point_count( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_get_point_count"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_get_point_count"); return 1; } @@ -598,19 +598,19 @@ laszip_set_header( { if (header == 0) { - sprintf(laszip_dll->error, "laszip_header_struct pointer 'header' is zero"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "laszip_header_struct pointer 'header' is zero"); return 1; } if (laszip_dll->reader) { - sprintf(laszip_dll->error, "cannot set header after reader was opened"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot set header after reader was opened"); return 1; } if (laszip_dll->writer) { - sprintf(laszip_dll->error, "cannot set header after writer was opened"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot set header after writer was opened"); return 1; } @@ -681,7 +681,7 @@ laszip_set_header( { if (header->user_data_in_header == 0) { - sprintf(laszip_dll->error, "header->user_data_in_header_size is %d but header->user_data_in_header is NULL", header->user_data_in_header_size); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "header->user_data_in_header_size is %d but header->user_data_in_header is NULL", header->user_data_in_header_size); return 1; } laszip_dll->header.user_data_in_header = new U8[header->user_data_in_header_size]; @@ -714,7 +714,7 @@ laszip_set_header( { if (header->vlrs[i].data == 0) { - sprintf(laszip_dll->error, "header->vlrs[%d].record_length_after_header is %d but header->vlrs[%d].data is NULL", i, header->vlrs[i].record_length_after_header, i); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "header->vlrs[%d].record_length_after_header is %d but header->vlrs[%d].data is NULL", i, header->vlrs[i].record_length_after_header, i); return 1; } laszip_dll->header.vlrs[i].data = new U8[header->vlrs[i].record_length_after_header]; @@ -734,7 +734,7 @@ laszip_set_header( laszip_dll->attributer = new LASattributer; if (laszip_dll->attributer == 0) { - sprintf(laszip_dll->error, "cannot allocate LASattributer"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot allocate LASattributer"); return 1; } } @@ -753,7 +753,7 @@ laszip_set_header( { if (header->user_data_after_header == 0) { - sprintf(laszip_dll->error, "header->user_data_after_header_size is %d but header->user_data_after_header is NULL", header->user_data_after_header_size); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "header->user_data_after_header_size is %d but header->user_data_after_header is NULL", header->user_data_after_header_size); return 1; } laszip_dll->header.user_data_after_header = new U8[header->user_data_after_header_size]; @@ -762,7 +762,7 @@ laszip_set_header( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_set_header"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_set_header"); return 1; } @@ -785,13 +785,13 @@ laszip_set_point_type_and_size( { if (laszip_dll->reader) { - sprintf(laszip_dll->error, "cannot set point format and point size after reader was opened"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot set point format and point size after reader was opened"); return 1; } if (laszip_dll->writer) { - sprintf(laszip_dll->error, "cannot set point format and point size after writer was opened"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot set point format and point size after writer was opened"); return 1; } @@ -799,7 +799,7 @@ laszip_set_point_type_and_size( if (!LASzip().setup(point_type, point_size, LASZIP_COMPRESSOR_NONE)) { - sprintf(laszip_dll->error, "invalid combination of point_type %d and point_size %d", (I32)point_type, (I32)point_size); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "invalid combination of point_type %d and point_size %d", (I32)point_type, (I32)point_size); return 1; } @@ -810,7 +810,7 @@ laszip_set_point_type_and_size( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_set_point_type_and_size"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_set_point_type_and_size"); return 1; } @@ -853,38 +853,38 @@ laszip_check_for_integer_overflow( if ((header->min_x > 0) != (dequant_min_x > 0)) { - sprintf(laszip_dll->error, "quantization sign flip for min_x from %g to %g. set scale factor for x coarser than %g\n", header->min_x, dequant_min_x, header->x_scale_factor); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "quantization sign flip for min_x from %g to %g. set scale factor for x coarser than %g\n", header->min_x, dequant_min_x, header->x_scale_factor); return 1; } if ((header->max_x > 0) != (dequant_max_x > 0)) { - sprintf(laszip_dll->error, "quantization sign flip for max_x from %g to %g. set scale factor for x coarser than %g\n", header->max_x, dequant_max_x, header->x_scale_factor); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "quantization sign flip for max_x from %g to %g. set scale factor for x coarser than %g\n", header->max_x, dequant_max_x, header->x_scale_factor); return 1; } if ((header->min_y > 0) != (dequant_min_y > 0)) { - sprintf(laszip_dll->error, "quantization sign flip for min_y from %g to %g. set scale factor for y coarser than %g\n", header->min_y, dequant_min_y, header->y_scale_factor); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "quantization sign flip for min_y from %g to %g. set scale factor for y coarser than %g\n", header->min_y, dequant_min_y, header->y_scale_factor); return 1; } if ((header->max_y > 0) != (dequant_max_y > 0)) { - sprintf(laszip_dll->error, "quantization sign flip for max_y from %g to %g. set scale factor for y coarser than %g\n", header->max_y, dequant_max_y, header->y_scale_factor); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "quantization sign flip for max_y from %g to %g. set scale factor for y coarser than %g\n", header->max_y, dequant_max_y, header->y_scale_factor); return 1; } if ((header->min_z > 0) != (dequant_min_z > 0)) { - sprintf(laszip_dll->error, "quantization sign flip for min_z from %g to %g. set scale factor for z coarser than %g\n", header->min_z, dequant_min_z, header->z_scale_factor); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "quantization sign flip for min_z from %g to %g. set scale factor for z coarser than %g\n", header->min_z, dequant_min_z, header->z_scale_factor); return 1; } if ((header->max_z > 0) != (dequant_max_z > 0)) { - sprintf(laszip_dll->error, "quantization sign flip for max_z from %g to %g. set scale factor for z coarser than %g\n", header->max_z, dequant_max_z, header->z_scale_factor); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "quantization sign flip for max_z from %g to %g. set scale factor for z coarser than %g\n", header->max_z, dequant_max_z, header->z_scale_factor); return 1; } } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_auto_offset"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_auto_offset"); return 1; } @@ -905,13 +905,13 @@ laszip_auto_offset( { if (laszip_dll->reader) { - sprintf(laszip_dll->error, "cannot auto offset after reader was opened"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot auto offset after reader was opened"); return 1; } if (laszip_dll->writer) { - sprintf(laszip_dll->error, "cannot auto offset after writer was opened"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot auto offset after writer was opened"); return 1; } @@ -927,19 +927,19 @@ laszip_auto_offset( if ((x_scale_factor <= 0) || !F64_IS_FINITE(x_scale_factor)) { - sprintf(laszip_dll->error, "invalid x scale_factor %g in header", header->x_scale_factor); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "invalid x scale_factor %g in header", header->x_scale_factor); return 1; } if ((y_scale_factor <= 0) || !F64_IS_FINITE(y_scale_factor)) { - sprintf(laszip_dll->error, "invalid y scale_factor %g in header", header->y_scale_factor); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "invalid y scale_factor %g in header", header->y_scale_factor); return 1; } if ((z_scale_factor <= 0) || !F64_IS_FINITE(z_scale_factor)) { - sprintf(laszip_dll->error, "invalid z scale_factor %g in header", header->z_scale_factor); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "invalid z scale_factor %g in header", header->z_scale_factor); return 1; } @@ -949,19 +949,19 @@ laszip_auto_offset( if (!F64_IS_FINITE(center_bb_x)) { - sprintf(laszip_dll->error, "invalid x coordinate at center of bounding box (min: %g max: %g)", header->min_x, header->max_x); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "invalid x coordinate at center of bounding box (min: %g max: %g)", header->min_x, header->max_x); return 1; } if (!F64_IS_FINITE(center_bb_y)) { - sprintf(laszip_dll->error, "invalid y coordinate at center of bounding box (min: %g max: %g)", header->min_y, header->max_y); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "invalid y coordinate at center of bounding box (min: %g max: %g)", header->min_y, header->max_y); return 1; } if (!F64_IS_FINITE(center_bb_z)) { - sprintf(laszip_dll->error, "invalid z coordinate at center of bounding box (min: %g max: %g)", header->min_z, header->max_z); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "invalid z coordinate at center of bounding box (min: %g max: %g)", header->min_z, header->max_z); return 1; } @@ -983,7 +983,7 @@ laszip_auto_offset( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_auto_offset"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_auto_offset"); return 1; } @@ -1005,13 +1005,13 @@ laszip_set_point( { if (point == 0) { - sprintf(laszip_dll->error, "laszip_point_struct pointer 'point' is zero"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "laszip_point_struct pointer 'point' is zero"); return 1; } if (laszip_dll->reader) { - sprintf(laszip_dll->error, "cannot set point for reader"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot set point for reader"); return 1; } @@ -1027,13 +1027,13 @@ laszip_set_point( } else { - sprintf(laszip_dll->error, "target point has %d extra bytes but source point has %d", laszip_dll->point.num_extra_bytes, point->num_extra_bytes); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "target point has %d extra bytes but source point has %d", laszip_dll->point.num_extra_bytes, point->num_extra_bytes); return 1; } } else if (!laszip_dll->compatibility_mode) { - sprintf(laszip_dll->error, "target point has extra bytes but source point does not"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "target point has extra bytes but source point does not"); return 1; } } @@ -1042,7 +1042,7 @@ laszip_set_point( { if (point->extra_bytes) { - sprintf(laszip_dll->error, "source point has extra bytes but target point does not"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "source point has extra bytes but target point does not"); return 1; } } @@ -1050,7 +1050,7 @@ laszip_set_point( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_set_point"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_set_point"); return 1; } @@ -1072,13 +1072,13 @@ laszip_set_coordinates( { if (coordinates == 0) { - sprintf(laszip_dll->error, "laszip_F64 pointer 'coordinates' is zero"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "laszip_F64 pointer 'coordinates' is zero"); return 1; } if (laszip_dll->reader) { - sprintf(laszip_dll->error, "cannot set coordinates for reader"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot set coordinates for reader"); return 1; } @@ -1098,7 +1098,7 @@ laszip_set_coordinates( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_set_coordinates"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_set_coordinates"); return 1; } @@ -1120,7 +1120,7 @@ laszip_get_coordinates( { if (coordinates == 0) { - sprintf(laszip_dll->error, "laszip_F64 pointer 'coordinates' is zero"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "laszip_F64 pointer 'coordinates' is zero"); return 1; } @@ -1140,7 +1140,7 @@ laszip_get_coordinates( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_get_coordinates"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_get_coordinates"); return 1; } @@ -1163,25 +1163,25 @@ laszip_set_geokeys( { if (number == 0) { - sprintf(laszip_dll->error, "number of key_entries is zero"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "number of key_entries is zero"); return 1; } if (key_entries == 0) { - sprintf(laszip_dll->error, "laszip_geokey_struct pointer 'key_entries' is zero"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "laszip_geokey_struct pointer 'key_entries' is zero"); return 1; } if (laszip_dll->reader) { - sprintf(laszip_dll->error, "cannot set geokeys after reader was opened"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot set geokeys after reader was opened"); return 1; } if (laszip_dll->writer) { - sprintf(laszip_dll->error, "cannot set geokeys after writer was opened"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot set geokeys after writer was opened"); return 1; } @@ -1190,7 +1190,7 @@ laszip_set_geokeys( laszip_geokey_struct* key_entries_plus_one = new laszip_geokey_struct[number+1]; if (key_entries_plus_one == 0) { - sprintf(laszip_dll->error, "allocating laszip_geokey_struct[%u] array", number+1); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "allocating laszip_geokey_struct[%u] array", number+1); return 1; } key_entries_plus_one[0].key_id = 1; // aka key_directory_version @@ -1203,13 +1203,13 @@ laszip_set_geokeys( if (laszip_add_vlr(laszip_dll, "LASF_Projection", 34735, (laszip_U16)(8 + number*8), 0, (laszip_U8*)key_entries_plus_one)) { - sprintf(laszip_dll->error, "setting %u geodouble_params", number); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "setting %u geodouble_params", number); return 1; } } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_set_geokey_entries"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_set_geokey_entries"); return 1; } @@ -1232,25 +1232,25 @@ laszip_set_geodouble_params( { if (number == 0) { - sprintf(laszip_dll->error, "number of geodouble_params is zero"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "number of geodouble_params is zero"); return 1; } if (geodouble_params == 0) { - sprintf(laszip_dll->error, "laszip_F64 pointer 'geodouble_params' is zero"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "laszip_F64 pointer 'geodouble_params' is zero"); return 1; } if (laszip_dll->reader) { - sprintf(laszip_dll->error, "cannot set geodouble_params after reader was opened"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot set geodouble_params after reader was opened"); return 1; } if (laszip_dll->writer) { - sprintf(laszip_dll->error, "cannot set geodouble_params after writer was opened"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot set geodouble_params after writer was opened"); return 1; } @@ -1258,13 +1258,13 @@ laszip_set_geodouble_params( if (laszip_add_vlr(laszip_dll, "LASF_Projection", 34736, (laszip_U16)(number*8), 0, (laszip_U8*)geodouble_params)) { - sprintf(laszip_dll->error, "setting %u geodouble_params", number); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "setting %u geodouble_params", number); return 1; } } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_set_geodouble_params"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_set_geodouble_params"); return 1; } @@ -1287,25 +1287,25 @@ laszip_set_geoascii_params( { if (number == 0) { - sprintf(laszip_dll->error, "number of geoascii_params is zero"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "number of geoascii_params is zero"); return 1; } if (geoascii_params == 0) { - sprintf(laszip_dll->error, "laszip_CHAR pointer 'geoascii_params' is zero"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "laszip_CHAR pointer 'geoascii_params' is zero"); return 1; } if (laszip_dll->reader) { - sprintf(laszip_dll->error, "cannot set geoascii_params after reader was opened"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot set geoascii_params after reader was opened"); return 1; } if (laszip_dll->writer) { - sprintf(laszip_dll->error, "cannot set geoascii_params after writer was opened"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot set geoascii_params after writer was opened"); return 1; } @@ -1313,13 +1313,13 @@ laszip_set_geoascii_params( if (laszip_add_vlr(laszip_dll, "LASF_Projection", 34737, (laszip_U16)(number), 0, (laszip_U8*)geoascii_params)) { - sprintf(laszip_dll->error, "setting %u geoascii_params", number); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "setting %u geoascii_params", number); return 1; } } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_set_geoascii_params"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_set_geoascii_params"); return 1; } @@ -1345,25 +1345,25 @@ laszip_add_attribute( { if (type > LAS_ATTRIBUTE_F64) { - sprintf(laszip_dll->error, "laszip_U32 'type' is %u but needs to be between %d and %d", type, LAS_ATTRIBUTE_U8, LAS_ATTRIBUTE_F64); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "laszip_U32 'type' is %u but needs to be between %d and %d", type, LAS_ATTRIBUTE_U8, LAS_ATTRIBUTE_F64); return 1; } if (name == 0) { - sprintf(laszip_dll->error, "laszip_CHAR pointer 'name' is zero"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "laszip_CHAR pointer 'name' is zero"); return 1; } if (laszip_dll->reader) { - sprintf(laszip_dll->error, "cannot add attribute after reader was opened"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot add attribute after reader was opened"); return 1; } if (laszip_dll->writer) { - sprintf(laszip_dll->error, "cannot add attribute after writer was opened"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot add attribute after writer was opened"); return 1; } @@ -1376,26 +1376,26 @@ laszip_add_attribute( laszip_dll->attributer = new LASattributer; if (laszip_dll->attributer == 0) { - sprintf(laszip_dll->error, "cannot allocate LASattributer"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot allocate LASattributer"); return 1; } } if (laszip_dll->attributer->add_attribute(lasattribute) == -1) { - sprintf(laszip_dll->error, "cannot add attribute '%s' to attributer", name); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot add attribute '%s' to attributer", name); return 1; } if (laszip_add_vlr(laszip_dll, "LASF_Spec\0\0\0\0\0\0", 4, (laszip_U16)(laszip_dll->attributer->number_attributes*sizeof(LASattribute)), 0, (laszip_U8*)laszip_dll->attributer->attributes)) { - sprintf(laszip_dll->error, "adding the new extra bytes VLR with the additional attribute '%s'", name); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "adding the new extra bytes VLR with the additional attribute '%s'", name); return 1; } } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_add_attribute"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_add_attribute"); return 1; } @@ -1421,25 +1421,25 @@ laszip_add_vlr( { if (user_id == 0) { - sprintf(laszip_dll->error, "laszip_CHAR pointer 'user_id' is zero"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "laszip_CHAR pointer 'user_id' is zero"); return 1; } if ((record_length_after_header > 0) && (data == 0)) { - sprintf(laszip_dll->error, "record_length_after_header of VLR is %u but data pointer is zero", (U32)record_length_after_header); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "record_length_after_header of VLR is %u but data pointer is zero", (U32)record_length_after_header); return 1; } if (laszip_dll->reader) { - sprintf(laszip_dll->error, "cannot add vlr after reader was opened"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot add vlr after reader was opened"); return 1; } if (laszip_dll->writer) { - sprintf(laszip_dll->error, "cannot add vlr after writer was opened"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot add vlr after writer was opened"); return 1; } @@ -1473,7 +1473,7 @@ laszip_add_vlr( laszip_dll->header.vlrs = (laszip_vlr_struct*)realloc(laszip_dll->header.vlrs, sizeof(laszip_vlr_struct)*laszip_dll->header.number_of_variable_length_records); if (laszip_dll->header.vlrs == 0) { - sprintf(laszip_dll->error, "reallocating vlrs[%u] array", laszip_dll->header.number_of_variable_length_records); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reallocating vlrs[%u] array", laszip_dll->header.number_of_variable_length_records); return 1; } } @@ -1485,7 +1485,7 @@ laszip_add_vlr( laszip_dll->header.vlrs = (laszip_vlr_struct*)malloc(sizeof(laszip_vlr_struct)); if (laszip_dll->header.vlrs == 0) { - sprintf(laszip_dll->error, "allocating vlrs[1] array"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "allocating vlrs[1] array"); return 1; } } @@ -1506,7 +1506,7 @@ laszip_add_vlr( } else { - sprintf(laszip_dll->header.vlrs[i].description, "LASzip DLL %d.%d r%d (%d)", LASZIP_VERSION_MAJOR, LASZIP_VERSION_MINOR, LASZIP_VERSION_REVISION, LASZIP_VERSION_BUILD_DATE); + snprintf(laszip_dll->header.vlrs[i].description, sizeof(laszip_dll->header.vlrs[i].description), "LASzip DLL %d.%d r%d (%d)", LASZIP_VERSION_MAJOR, LASZIP_VERSION_MINOR, LASZIP_VERSION_REVISION, LASZIP_VERSION_BUILD_DATE); } if (record_length_after_header) { @@ -1517,7 +1517,7 @@ laszip_add_vlr( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_add_vlr"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_add_vlr"); return 1; } @@ -1540,19 +1540,19 @@ laszip_remove_vlr( { if (user_id == 0) { - sprintf(laszip_dll->error, "laszip_CHAR pointer 'user_id' is zero"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "laszip_CHAR pointer 'user_id' is zero"); return 1; } if (laszip_dll->reader) { - sprintf(laszip_dll->error, "cannot remove vlr after reader was opened"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot remove vlr after reader was opened"); return 1; } if (laszip_dll->writer) { - sprintf(laszip_dll->error, "cannot remove vlr after writer was opened"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot remove vlr after writer was opened"); return 1; } @@ -1580,7 +1580,7 @@ laszip_remove_vlr( laszip_dll->header.vlrs = (laszip_vlr_struct*)realloc(laszip_dll->header.vlrs, sizeof(laszip_vlr_struct)*laszip_dll->header.number_of_variable_length_records); if (laszip_dll->header.vlrs == 0) { - sprintf(laszip_dll->error, "reallocating vlrs[%u] array", laszip_dll->header.number_of_variable_length_records); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reallocating vlrs[%u] array", laszip_dll->header.number_of_variable_length_records); return 1; } } @@ -1595,19 +1595,19 @@ laszip_remove_vlr( } if (i != U32_MAX) { - sprintf(laszip_dll->error, "cannot find VLR with user_id '%s' and record_id %d among the %u VLRs in the header", user_id, (I32)record_id, laszip_dll->header.number_of_variable_length_records); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot find VLR with user_id '%s' and record_id %d among the %u VLRs in the header", user_id, (I32)record_id, laszip_dll->header.number_of_variable_length_records); return 1; } } else { - sprintf(laszip_dll->error, "cannot remove VLR with user_id '%s' and record_id %d because header has no VLRs", user_id, (I32)record_id); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot remove VLR with user_id '%s' and record_id %d because header has no VLRs", user_id, (I32)record_id); return 1; } } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_add_vlr"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_add_vlr"); return 1; } @@ -1629,13 +1629,13 @@ laszip_preserve_generating_software( { if (laszip_dll->reader) { - sprintf(laszip_dll->error, "reader is already open"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reader is already open"); return 1; } if (laszip_dll->writer) { - sprintf(laszip_dll->error, "writer is already open"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writer is already open"); return 1; } @@ -1643,7 +1643,7 @@ laszip_preserve_generating_software( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_preserve_generating_software"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_preserve_generating_software"); return 1; } @@ -1666,13 +1666,13 @@ laszip_request_native_extension( { if (laszip_dll->reader) { - sprintf(laszip_dll->error, "reader is already open"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reader is already open"); return 1; } if (laszip_dll->writer) { - sprintf(laszip_dll->error, "writer is already open"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writer is already open"); return 1; } @@ -1685,7 +1685,7 @@ laszip_request_native_extension( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_request_native_extension"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_request_native_extension"); return 1; } @@ -1707,13 +1707,13 @@ laszip_request_compatibility_mode( { if (laszip_dll->reader) { - sprintf(laszip_dll->error, "reader is already open"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reader is already open"); return 1; } if (laszip_dll->writer) { - sprintf(laszip_dll->error, "writer is already open"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writer is already open"); return 1; } @@ -1726,7 +1726,7 @@ laszip_request_compatibility_mode( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_request_compatibility_mode"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_request_compatibility_mode"); return 1; } @@ -1748,13 +1748,13 @@ laszip_set_chunk_size( { if (laszip_dll->reader) { - sprintf(laszip_dll->error, "reader is already open"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reader is already open"); return 1; } if (laszip_dll->writer) { - sprintf(laszip_dll->error, "writer is already open"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writer is already open"); return 1; } @@ -1762,7 +1762,7 @@ laszip_set_chunk_size( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_set_chunk_size"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_set_chunk_size"); return 1; } @@ -1785,19 +1785,19 @@ laszip_create_spatial_index( { if (laszip_dll->reader) { - sprintf(laszip_dll->error, "reader is already open"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reader is already open"); return 1; } if (laszip_dll->writer) { - sprintf(laszip_dll->error, "writer is already open"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writer is already open"); return 1; } if (append) { - sprintf(laszip_dll->error, "appending of spatial index not (yet) supported in this version"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "appending of spatial index not (yet) supported in this version"); return 1; } @@ -1806,7 +1806,7 @@ laszip_create_spatial_index( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_create_spatial_index"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_create_spatial_index"); return 1; } @@ -1822,7 +1822,7 @@ laszip_prepare_header_for_write( { if ((laszip_dll->header.version_major != 1) || (laszip_dll->header.version_minor > 4)) { - sprintf(laszip_dll->error, "unknown LAS version %d.%d", (I32)laszip_dll->header.version_major, (I32)laszip_dll->header.version_minor); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "unknown LAS version %d.%d", (I32)laszip_dll->header.version_major, (I32)laszip_dll->header.version_minor); return 1; } @@ -1848,9 +1848,9 @@ laszip_prepare_header_for_write( if (laszip_dll->header.number_of_point_records != 0) { #ifdef _WIN32 - sprintf(laszip_dll->error, "inconsistent number_of_point_records %u and extended_number_of_point_records %I64d", laszip_dll->header.number_of_point_records, laszip_dll->header.extended_number_of_point_records); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "inconsistent number_of_point_records %u and extended_number_of_point_records %I64d", laszip_dll->header.number_of_point_records, laszip_dll->header.extended_number_of_point_records); #else - sprintf(laszip_dll->error, "inconsistent number_of_point_records %u and extended_number_of_point_records %llu", laszip_dll->header.number_of_point_records, laszip_dll->header.extended_number_of_point_records); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "inconsistent number_of_point_records %u and extended_number_of_point_records %llu", laszip_dll->header.number_of_point_records, laszip_dll->header.extended_number_of_point_records); #endif return 1; } @@ -1866,9 +1866,9 @@ laszip_prepare_header_for_write( if (laszip_dll->header.number_of_points_by_return[i] != 0) { #ifdef _WIN32 - sprintf(laszip_dll->error, "inconsistent number_of_points_by_return[%u] %u and extended_number_of_points_by_return[%u] %I64d", i, laszip_dll->header.number_of_points_by_return[i], i, laszip_dll->header.extended_number_of_points_by_return[i]); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "inconsistent number_of_points_by_return[%u] %u and extended_number_of_points_by_return[%u] %I64d", i, laszip_dll->header.number_of_points_by_return[i], i, laszip_dll->header.extended_number_of_points_by_return[i]); #else - sprintf(laszip_dll->error, "inconsistent number_of_points_by_return[%u] %u and extended_number_of_points_by_return[%u] %llu", i, laszip_dll->header.number_of_points_by_return[i], i, laszip_dll->header.extended_number_of_points_by_return[i]); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "inconsistent number_of_points_by_return[%u] %u and extended_number_of_points_by_return[%u] %llu", i, laszip_dll->header.number_of_points_by_return[i], i, laszip_dll->header.extended_number_of_points_by_return[i]); #endif return 1; } @@ -1915,9 +1915,9 @@ laszip_prepare_point_for_write( if (laszip_dll->header.extended_number_of_point_records > U32_MAX) { #ifdef _WIN32 - sprintf(laszip_dll->error, "extended_number_of_point_records of %I64d is too much for 32-bit counters of compatibility mode", laszip_dll->header.extended_number_of_point_records); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "extended_number_of_point_records of %I64d is too much for 32-bit counters of compatibility mode", laszip_dll->header.extended_number_of_point_records); #else - sprintf(laszip_dll->error, "extended_number_of_point_records of %llu is too much for 32-bit counters of compatibility mode", laszip_dll->header.extended_number_of_point_records); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "extended_number_of_point_records of %llu is too much for 32-bit counters of compatibility mode", laszip_dll->header.extended_number_of_point_records); #endif return 1; } @@ -1952,13 +1952,13 @@ laszip_prepare_point_for_write( number_of_existing_extrabytes = laszip_dll->header.point_data_record_length - 67; break; default: - sprintf(laszip_dll->error, "unknown point_data_format %d", laszip_dll->header.point_data_format); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "unknown point_data_format %d", laszip_dll->header.point_data_format); return 1; } if (number_of_existing_extrabytes < 0) { - sprintf(laszip_dll->error, "bad point_data_format %d point_data_record_length %d combination", laszip_dll->header.point_data_format, laszip_dll->header.point_data_record_length); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "bad point_data_format %d point_data_record_length %d combination", laszip_dll->header.point_data_format, laszip_dll->header.point_data_record_length); return 1; } @@ -2048,7 +2048,7 @@ laszip_prepare_point_for_write( if (laszip_add_vlr(laszip_dll, "lascompatible\0\0", 22204, (laszip_U16)(2+2+4+148), 0, (laszip_U8*)out->takeData())) { - sprintf(laszip_dll->error, "adding the compatibility VLR"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "adding the compatibility VLR"); return 1; } delete out; @@ -2060,7 +2060,7 @@ laszip_prepare_point_for_write( laszip_dll->attributer = new LASattributer; if (laszip_dll->attributer == 0) { - sprintf(laszip_dll->error, "cannot allocate LASattributer"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot allocate LASattributer"); return 1; } } @@ -2073,7 +2073,7 @@ laszip_prepare_point_for_write( if (laszip_dll->attributer->get_attributes_size() > number_of_existing_extrabytes) { - sprintf(laszip_dll->error, "bad \"extra bytes\" VLR describes %d bytes more than points actually have", laszip_dll->attributer->get_attributes_size() - number_of_existing_extrabytes); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "bad \"extra bytes\" VLR describes %d bytes more than points actually have", laszip_dll->attributer->get_attributes_size() - number_of_existing_extrabytes); return 1; } else if (laszip_dll->attributer->get_attributes_size() < number_of_existing_extrabytes) @@ -2095,11 +2095,11 @@ laszip_prepare_point_for_write( { CHAR unknown_name[16]; memset(unknown_name, 0, 16); - sprintf(unknown_name, "unknown %d", i); + snprintf(unknown_name, sizeof(unknown_name), "unknown %d", i); LASattribute lasattribute_unknown(LAS_ATTRIBUTE_U8, unknown_name, unknown_name); if (laszip_dll->attributer->add_attribute(lasattribute_unknown) == -1) { - sprintf(laszip_dll->error, "cannot add unknown U8 attribute '%s' of %d to attributer", unknown_name, number_of_existing_extrabytes); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot add unknown U8 attribute '%s' of %d to attributer", unknown_name, number_of_existing_extrabytes); return 1; } } @@ -2142,7 +2142,7 @@ laszip_prepare_point_for_write( if (laszip_add_vlr(laszip_dll, "LASF_Spec\0\0\0\0\0\0", 4, (laszip_U16)(laszip_dll->attributer->number_attributes*sizeof(LASattribute)), 0, (laszip_U8*)laszip_dll->attributer->attributes)) { - sprintf(laszip_dll->error, "adding the extra bytes VLR with the additional attributes"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "adding the extra bytes VLR with the additional attributes"); return 1; } @@ -2166,7 +2166,7 @@ laszip_prepare_point_for_write( } else if (compress) { - sprintf(laszip_dll->error, "LASzip DLL %d.%d r%d (%d) cannot compress point data format %d without requesting 'compatibility mode'", LASZIP_VERSION_MAJOR, LASZIP_VERSION_MINOR, LASZIP_VERSION_REVISION, LASZIP_VERSION_BUILD_DATE, (I32)laszip_dll->header.point_data_format); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "LASzip DLL %d.%d r%d (%d) cannot compress point data format %d without requesting 'compatibility mode'", LASZIP_VERSION_MAJOR, LASZIP_VERSION_MINOR, LASZIP_VERSION_REVISION, LASZIP_VERSION_BUILD_DATE, (I32)laszip_dll->header.point_data_format); return 1; } } @@ -2196,7 +2196,7 @@ laszip_prepare_vlrs_for_write( { if (laszip_dll->header.vlrs == 0) { - sprintf(laszip_dll->error, "number_of_variable_length_records is %u but vlrs pointer is zero", laszip_dll->header.number_of_variable_length_records); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "number_of_variable_length_records is %u but vlrs pointer is zero", laszip_dll->header.number_of_variable_length_records); return 1; } @@ -2207,7 +2207,7 @@ laszip_prepare_vlrs_for_write( { if (laszip_dll->header.vlrs == 0) { - sprintf(laszip_dll->error, "vlrs[%u].record_length_after_header is %u but vlrs[%u].data pointer is zero", i, laszip_dll->header.vlrs[i].record_length_after_header, i); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "vlrs[%u].record_length_after_header is %u but vlrs[%u].data pointer is zero", i, laszip_dll->header.vlrs[i].record_length_after_header, i); return 1; } vlrs_size += laszip_dll->header.vlrs[i].record_length_after_header; @@ -2217,7 +2217,7 @@ laszip_prepare_vlrs_for_write( if ((vlrs_size + laszip_dll->header.header_size + laszip_dll->header.user_data_after_header_size) != laszip_dll->header.offset_to_point_data) { - sprintf(laszip_dll->error,"header_size (%u) plus vlrs_size (%u) plus user_data_after_header_size (%u) does not equal offset_to_point_data (%u)", (U32)laszip_dll->header.header_size, vlrs_size, laszip_dll->header.user_data_after_header_size, laszip_dll->header.offset_to_point_data); + snprintf(laszip_dll->error, sizeof(laszip_dll->error),"header_size (%u) plus vlrs_size (%u) plus user_data_after_header_size (%u) does not equal offset_to_point_data (%u)", (U32)laszip_dll->header.header_size, vlrs_size, laszip_dll->header.user_data_after_header_size, laszip_dll->header.offset_to_point_data); return 1; } @@ -2246,33 +2246,33 @@ write_laszip_vlr_header( U16 reserved = 0x0; try { out->put16bitsLE((U8*)&reserved); } catch(...) { - sprintf(laszip_dll->error, "writing LASzip VLR header.reserved"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing LASzip VLR header.reserved"); return 1; } U8 user_id[16] = "laszip encoded\0"; try { out->putBytes((U8*)user_id, 16); } catch(...) { - sprintf(laszip_dll->error, "writing LASzip VLR header.user_id"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing LASzip VLR header.user_id"); return 1; } U16 record_id = 22204; try { out->put16bitsLE((U8*)&record_id); } catch(...) { - sprintf(laszip_dll->error, "writing LASzip VLR header.record_id"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing LASzip VLR header.record_id"); return 1; } U16 record_length_after_header = (U16)laszip_vrl_payload_size(laszip); try { out->put16bitsLE((U8*)&record_length_after_header); } catch(...) { - sprintf(laszip_dll->error, "writing LASzip VLR header.record_length_after_header"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing LASzip VLR header.record_length_after_header"); return 1; } CHAR description[32]; memset(description, 0, 32); - sprintf(description, "LASzip DLL %d.%d r%d (%d)", LASZIP_VERSION_MAJOR, LASZIP_VERSION_MINOR, LASZIP_VERSION_REVISION, LASZIP_VERSION_BUILD_DATE); + snprintf(description, sizeof(description), "LASzip DLL %d.%d r%d (%d)", LASZIP_VERSION_MAJOR, LASZIP_VERSION_MINOR, LASZIP_VERSION_REVISION, LASZIP_VERSION_BUILD_DATE); try { out->putBytes((U8*)description, 32); } catch(...) { - sprintf(laszip_dll->error, "writing LASzip VLR header.description"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing LASzip VLR header.description"); return 1; } @@ -2306,52 +2306,52 @@ write_laszip_vlr_payload( try { out->put16bitsLE((const U8*)&(laszip->compressor)); } catch(...) { - sprintf(laszip_dll->error, "writing compressor %d", (I32)laszip->compressor); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing compressor %d", (I32)laszip->compressor); return 1; } try { out->put16bitsLE((const U8*)&(laszip->coder)); } catch(...) { - sprintf(laszip_dll->error, "writing coder %d", (I32)laszip->coder); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing coder %d", (I32)laszip->coder); return 1; } try { out->putBytes((const U8*)&(laszip->version_major), 1); } catch(...) { - sprintf(laszip_dll->error, "writing version_major %d", (I32)laszip->version_major); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing version_major %d", (I32)laszip->version_major); return 1; } try { out->putBytes((const U8*)&(laszip->version_minor), 1); } catch(...) { - sprintf(laszip_dll->error, "writing version_minor %d", (I32)laszip->version_minor); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing version_minor %d", (I32)laszip->version_minor); return 1; } try { out->put16bitsLE((const U8*)&(laszip->version_revision)); } catch(...) { - sprintf(laszip_dll->error, "writing version_revision %d", (I32)laszip->version_revision); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing version_revision %d", (I32)laszip->version_revision); return 1; } try { out->put32bitsLE((const U8*)&(laszip->options)); } catch(...) { - sprintf(laszip_dll->error, "writing options %u", laszip->options); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing options %u", laszip->options); return 1; } try { out->put32bitsLE((const U8*)&(laszip->chunk_size)); } catch(...) { - sprintf(laszip_dll->error, "writing chunk_size %u", laszip->chunk_size); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing chunk_size %u", laszip->chunk_size); return 1; } try { out->put64bitsLE((const U8*)&(laszip->number_of_special_evlrs)); } catch(...) { - sprintf(laszip_dll->error, "writing number_of_special_evlrs %d", (I32)laszip->number_of_special_evlrs); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing number_of_special_evlrs %d", (I32)laszip->number_of_special_evlrs); return 1; } try { out->put64bitsLE((const U8*)&(laszip->offset_to_special_evlrs)); } catch(...) { - sprintf(laszip_dll->error, "writing offset_to_special_evlrs %d", (I32)laszip->offset_to_special_evlrs); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing offset_to_special_evlrs %d", (I32)laszip->offset_to_special_evlrs); return 1; } try { out->put16bitsLE((const U8*)&(laszip->num_items)); } catch(...) { - sprintf(laszip_dll->error, "writing num_items %d", (I32)laszip->num_items); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing num_items %d", (I32)laszip->num_items); return 1; } @@ -2361,17 +2361,17 @@ write_laszip_vlr_payload( U16 type = (U16)(laszip->items[j].type); try { out->put16bitsLE((const U8*)&type); } catch(...) { - sprintf(laszip_dll->error, "writing type %d of item %d", (I32)laszip->items[j].type, j); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing type %d of item %d", (I32)laszip->items[j].type, j); return 1; } try { out->put16bitsLE((const U8*)&(laszip->items[j].size)); } catch(...) { - sprintf(laszip_dll->error, "writing size %d of item %d", (I32)laszip->items[j].size, j); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing size %d of item %d", (I32)laszip->items[j].size, j); return 1; } try { out->put16bitsLE((const U8*)&(laszip->items[j].version)); } catch(...) { - sprintf(laszip_dll->error, "writing version %d of item %d", (I32)laszip->items[j].version, j); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing version %d of item %d", (I32)laszip->items[j].version, j); return 1; } } @@ -2390,77 +2390,77 @@ laszip_write_header( try { laszip_dll->streamout->putBytes((const U8*)"LASF", 4); } catch(...) { - sprintf(laszip_dll->error, "writing header.file_signature"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.file_signature"); return 1; } try { laszip_dll->streamout->put16bitsLE((const U8*)&(laszip_dll->header.file_source_ID)); } catch(...) { - sprintf(laszip_dll->error, "writing header.file_source_ID"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.file_source_ID"); return 1; } try { laszip_dll->streamout->put16bitsLE((const U8*)&(laszip_dll->header.global_encoding)); } catch(...) { - sprintf(laszip_dll->error, "writing header.global_encoding"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.global_encoding"); return 1; } try { laszip_dll->streamout->put32bitsLE((const U8*)&(laszip_dll->header.project_ID_GUID_data_1)); } catch(...) { - sprintf(laszip_dll->error, "writing header.project_ID_GUID_data_1"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.project_ID_GUID_data_1"); return 1; } try { laszip_dll->streamout->put16bitsLE((const U8*)&(laszip_dll->header.project_ID_GUID_data_2)); } catch(...) { - sprintf(laszip_dll->error, "writing header.project_ID_GUID_data_2"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.project_ID_GUID_data_2"); return 1; } try { laszip_dll->streamout->put16bitsLE((const U8*)&(laszip_dll->header.project_ID_GUID_data_3)); } catch(...) { - sprintf(laszip_dll->error, "writing header.project_ID_GUID_data_3"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.project_ID_GUID_data_3"); return 1; } try { laszip_dll->streamout->putBytes((const U8*)laszip_dll->header.project_ID_GUID_data_4, 8); } catch(...) { - sprintf(laszip_dll->error, "writing header.project_ID_GUID_data_4"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.project_ID_GUID_data_4"); return 1; } try { laszip_dll->streamout->putBytes((const U8*)&(laszip_dll->header.version_major), 1); } catch(...) { - sprintf(laszip_dll->error, "writing header.version_major"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.version_major"); return 1; } try { laszip_dll->streamout->putBytes((const U8*)&(laszip_dll->header.version_minor), 1); } catch(...) { - sprintf(laszip_dll->error, "writing header.version_minor"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.version_minor"); return 1; } try { laszip_dll->streamout->putBytes((const U8*)laszip_dll->header.system_identifier, 32); } catch(...) { - sprintf(laszip_dll->error, "writing header.system_identifier"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.system_identifier"); return 1; } if (!laszip_dll->preserve_generating_software) { memset(laszip_dll->header.generating_software, 0, 32); - sprintf(laszip_dll->header.generating_software, "LASzip DLL %d.%d r%d (%d)", LASZIP_VERSION_MAJOR, LASZIP_VERSION_MINOR, LASZIP_VERSION_REVISION, LASZIP_VERSION_BUILD_DATE); + snprintf(laszip_dll->header.generating_software, sizeof(laszip_dll->header.generating_software), "LASzip DLL %d.%d r%d (%d)", LASZIP_VERSION_MAJOR, LASZIP_VERSION_MINOR, LASZIP_VERSION_REVISION, LASZIP_VERSION_BUILD_DATE); } try { laszip_dll->streamout->putBytes((const U8*)laszip_dll->header.generating_software, 32); } catch(...) { - sprintf(laszip_dll->error, "writing header.generating_software"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.generating_software"); return 1; } try { laszip_dll->streamout->put16bitsLE((const U8*)&(laszip_dll->header.file_creation_day)); } catch(...) { - sprintf(laszip_dll->error, "writing header.file_creation_day"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.file_creation_day"); return 1; } try { laszip_dll->streamout->put16bitsLE((const U8*)&(laszip_dll->header.file_creation_year)); } catch(...) { - sprintf(laszip_dll->error, "writing header.file_creation_year"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.file_creation_year"); return 1; } try { laszip_dll->streamout->put16bitsLE((const U8*)&(laszip_dll->header.header_size)); } catch(...) { - sprintf(laszip_dll->error, "writing header.header_size"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.header_size"); return 1; } if (compress) @@ -2469,7 +2469,7 @@ laszip_write_header( } try { laszip_dll->streamout->put32bitsLE((const U8*)&(laszip_dll->header.offset_to_point_data)); } catch(...) { - sprintf(laszip_dll->error, "writing header.offset_to_point_data"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.offset_to_point_data"); return 1; } if (compress) @@ -2479,7 +2479,7 @@ laszip_write_header( } try { laszip_dll->streamout->put32bitsLE((const U8*)&(laszip_dll->header.number_of_variable_length_records)); } catch(...) { - sprintf(laszip_dll->error, "writing header.number_of_variable_length_records"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.number_of_variable_length_records"); return 1; } if (compress) @@ -2489,7 +2489,7 @@ laszip_write_header( } try { laszip_dll->streamout->putBytes((const U8*)&(laszip_dll->header.point_data_format), 1); } catch(...) { - sprintf(laszip_dll->error, "writing header.point_data_format"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.point_data_format"); return 1; } if (compress) @@ -2498,80 +2498,80 @@ laszip_write_header( } try { laszip_dll->streamout->put16bitsLE((const U8*)&(laszip_dll->header.point_data_record_length)); } catch(...) { - sprintf(laszip_dll->error, "writing header.point_data_record_length"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.point_data_record_length"); return 1; } try { laszip_dll->streamout->put32bitsLE((const U8*)&(laszip_dll->header.number_of_point_records)); } catch(...) { - sprintf(laszip_dll->error, "writing header.number_of_point_records"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.number_of_point_records"); return 1; } for (i = 0; i < 5; i++) { try { laszip_dll->streamout->put32bitsLE((const U8*)&(laszip_dll->header.number_of_points_by_return[i])); } catch(...) { - sprintf(laszip_dll->error, "writing header.number_of_points_by_return %d", i); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.number_of_points_by_return %d", i); return 1; } } try { laszip_dll->streamout->put64bitsLE((const U8*)&(laszip_dll->header.x_scale_factor)); } catch(...) { - sprintf(laszip_dll->error, "writing header.x_scale_factor"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.x_scale_factor"); return 1; } try { laszip_dll->streamout->put64bitsLE((const U8*)&(laszip_dll->header.y_scale_factor)); } catch(...) { - sprintf(laszip_dll->error, "writing header.y_scale_factor"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.y_scale_factor"); return 1; } try { laszip_dll->streamout->put64bitsLE((const U8*)&(laszip_dll->header.z_scale_factor)); } catch(...) { - sprintf(laszip_dll->error, "writing header.z_scale_factor"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.z_scale_factor"); return 1; } try { laszip_dll->streamout->put64bitsLE((const U8*)&(laszip_dll->header.x_offset)); } catch(...) { - sprintf(laszip_dll->error, "writing header.x_offset"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.x_offset"); return 1; } try { laszip_dll->streamout->put64bitsLE((const U8*)&(laszip_dll->header.y_offset)); } catch(...) { - sprintf(laszip_dll->error, "writing header.y_offset"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.y_offset"); return 1; } try { laszip_dll->streamout->put64bitsLE((const U8*)&(laszip_dll->header.z_offset)); } catch(...) { - sprintf(laszip_dll->error, "writing header.z_offset"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.z_offset"); return 1; } try { laszip_dll->streamout->put64bitsLE((const U8*)&(laszip_dll->header.max_x)); } catch(...) { - sprintf(laszip_dll->error, "writing header.max_x"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.max_x"); return 1; } try { laszip_dll->streamout->put64bitsLE((const U8*)&(laszip_dll->header.min_x)); } catch(...) { - sprintf(laszip_dll->error, "writing header.min_x"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.min_x"); return 1; } try { laszip_dll->streamout->put64bitsLE((const U8*)&(laszip_dll->header.max_y)); } catch(...) { - sprintf(laszip_dll->error, "writing header.max_y"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.max_y"); return 1; } try { laszip_dll->streamout->put64bitsLE((const U8*)&(laszip_dll->header.min_y)); } catch(...) { - sprintf(laszip_dll->error, "writing header.min_y"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.min_y"); return 1; } try { laszip_dll->streamout->put64bitsLE((const U8*)&(laszip_dll->header.max_z)); } catch(...) { - sprintf(laszip_dll->error, "writing header.max_z"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.max_z"); return 1; } try { laszip_dll->streamout->put64bitsLE((const U8*)&(laszip_dll->header.min_z)); } catch(...) { - sprintf(laszip_dll->error, "writing header.min_z"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.min_z"); return 1; } @@ -2580,7 +2580,7 @@ laszip_write_header( { if (laszip_dll->header.header_size < 235) { - sprintf(laszip_dll->error, "for LAS 1.%d header_size should at least be 235 but it is only %d", laszip_dll->header.version_minor, laszip_dll->header.header_size); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "for LAS 1.%d header_size should at least be 235 but it is only %d", laszip_dll->header.version_minor, laszip_dll->header.header_size); return 1; } else @@ -2588,15 +2588,15 @@ laszip_write_header( if (laszip_dll->header.start_of_waveform_data_packet_record != 0) { #ifdef _WIN32 - sprintf(laszip_dll->warning, "header.start_of_waveform_data_packet_record is %I64d. writing 0 instead.", laszip_dll->header.start_of_waveform_data_packet_record); + snprintf(laszip_dll->warning, sizeof(laszip_dll->warning), "header.start_of_waveform_data_packet_record is %I64d. writing 0 instead.", laszip_dll->header.start_of_waveform_data_packet_record); #else - sprintf(laszip_dll->warning, "header.start_of_waveform_data_packet_record is %llu. writing 0 instead.", laszip_dll->header.start_of_waveform_data_packet_record); + snprintf(laszip_dll->warning, sizeof(laszip_dll->warning), "header.start_of_waveform_data_packet_record is %llu. writing 0 instead.", laszip_dll->header.start_of_waveform_data_packet_record); #endif laszip_dll->header.start_of_waveform_data_packet_record = 0; } try { laszip_dll->streamout->put64bitsLE((const U8*)&(laszip_dll->header.start_of_waveform_data_packet_record)); } catch(...) { - sprintf(laszip_dll->error, "writing header.start_of_waveform_data_packet_record"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.start_of_waveform_data_packet_record"); return 1; } laszip_dll->header.user_data_in_header_size = laszip_dll->header.header_size - 235; @@ -2612,31 +2612,31 @@ laszip_write_header( { if (laszip_dll->header.header_size < 375) { - sprintf(laszip_dll->error, "for LAS 1.%d header_size should at least be 375 but it is only %d", laszip_dll->header.version_minor, laszip_dll->header.header_size); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "for LAS 1.%d header_size should at least be 375 but it is only %d", laszip_dll->header.version_minor, laszip_dll->header.header_size); return 1; } else { try { laszip_dll->streamout->put64bitsLE((const U8*)&(laszip_dll->header.start_of_first_extended_variable_length_record)); } catch(...) { - sprintf(laszip_dll->error, "writing header.start_of_first_extended_variable_length_record"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.start_of_first_extended_variable_length_record"); return 1; } try { laszip_dll->streamout->put32bitsLE((const U8*)&(laszip_dll->header.number_of_extended_variable_length_records)); } catch(...) { - sprintf(laszip_dll->error, "writing header.number_of_extended_variable_length_records"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.number_of_extended_variable_length_records"); return 1; } try { laszip_dll->streamout->put64bitsLE((const U8*)&(laszip_dll->header.extended_number_of_point_records)); } catch(...) { - sprintf(laszip_dll->error, "writing header.extended_number_of_point_records"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.extended_number_of_point_records"); return 1; } for (i = 0; i < 15; i++) { try { laszip_dll->streamout->put64bitsLE((const U8*)&(laszip_dll->header.extended_number_of_points_by_return[i])); } catch(...) { - sprintf(laszip_dll->error, "writing header.extended_number_of_points_by_return[%d]", i); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.extended_number_of_points_by_return[%d]", i); return 1; } } @@ -2649,7 +2649,7 @@ laszip_write_header( { try { laszip_dll->streamout->putBytes((const U8*)laszip_dll->header.user_data_in_header, laszip_dll->header.user_data_in_header_size); } catch(...) { - sprintf(laszip_dll->error, "writing %d bytes of data into header.user_data_in_header", laszip_dll->header.user_data_in_header_size); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing %d bytes of data into header.user_data_in_header", laszip_dll->header.user_data_in_header_size); return 1; } } @@ -2666,28 +2666,28 @@ laszip_write_header( try { laszip_dll->streamout->put16bitsLE((const U8*)&(laszip_dll->header.vlrs[i].reserved)); } catch(...) { - sprintf(laszip_dll->error, "writing header.vlrs[%d].reserved", i); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.vlrs[%d].reserved", i); return 1; } try { laszip_dll->streamout->putBytes((const U8*)laszip_dll->header.vlrs[i].user_id, 16); } catch(...) { - sprintf(laszip_dll->error, "writing header.vlrs[%d].user_id", i); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.vlrs[%d].user_id", i); return 1; } try { laszip_dll->streamout->put16bitsLE((const U8*)&(laszip_dll->header.vlrs[i].record_id)); } catch(...) { - sprintf(laszip_dll->error, "writing header.vlrs[%d].record_id", i); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.vlrs[%d].record_id", i); return 1; } try { laszip_dll->streamout->put16bitsLE((const U8*)&(laszip_dll->header.vlrs[i].record_length_after_header)); } catch(...) { - sprintf(laszip_dll->error, "writing header.vlrs[%d].record_length_after_header", i); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.vlrs[%d].record_length_after_header", i); return 1; } try { laszip_dll->streamout->putBytes((const U8*)laszip_dll->header.vlrs[i].description, 32); } catch(...) { - sprintf(laszip_dll->error, "writing header.vlrs[%d].description", i); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing header.vlrs[%d].description", i); return 1; } @@ -2697,7 +2697,7 @@ laszip_write_header( { try { laszip_dll->streamout->putBytes(laszip_dll->header.vlrs[i].data, laszip_dll->header.vlrs[i].record_length_after_header); } catch(...) { - sprintf(laszip_dll->error, "writing %d bytes of data into header.vlrs[%d].data", laszip_dll->header.vlrs[i].record_length_after_header, i); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing %d bytes of data into header.vlrs[%d].data", laszip_dll->header.vlrs[i].record_length_after_header, i); return 1; } } @@ -2727,7 +2727,7 @@ laszip_write_header( { try { laszip_dll->streamout->putBytes((const U8*)laszip_dll->header.user_data_after_header, laszip_dll->header.user_data_after_header_size); } catch(...) { - sprintf(laszip_dll->error, "writing %u bytes of data into header.user_data_after_header", laszip_dll->header.user_data_after_header_size); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing %u bytes of data into header.user_data_after_header", laszip_dll->header.user_data_after_header_size); return 1; } } @@ -2746,19 +2746,19 @@ laszip_I32 create_point_writer laszip_dll->writer = new LASwritePoint(); if (laszip_dll->writer == 0) { - sprintf(laszip_dll->error, "could not alloc LASwritePoint"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "could not alloc LASwritePoint"); return 1; } if (!laszip_dll->writer->setup(laszip->num_items, laszip->items, laszip)) { - sprintf(laszip_dll->error, "setup of LASwritePoint failed"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "setup of LASwritePoint failed"); return 1; } if (!laszip_dll->writer->init(laszip_dll->streamout)) { - sprintf(laszip_dll->error, "init of LASwritePoint failed"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "init of LASwritePoint failed"); return 1; } @@ -2780,7 +2780,7 @@ setup_laszip_items( { if (!laszip->request_compatibility_mode(1)) { - sprintf(laszip_dll->error, "requesting 'compatibility mode' has failed"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "requesting 'compatibility mode' has failed"); return 1; } } @@ -2789,7 +2789,7 @@ setup_laszip_items( if (!laszip->setup(point_type, point_size, LASZIP_COMPRESSOR_NONE)) { - sprintf(laszip_dll->error, "invalid combination of point_type %d and point_size %d", (I32)point_type, (I32)point_size); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "invalid combination of point_type %d and point_size %d", (I32)point_type, (I32)point_size); return 1; } @@ -2804,7 +2804,7 @@ setup_laszip_items( if (laszip_dll->point_items == 0) { - sprintf(laszip_dll->error, "could not alloc point_items"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "could not alloc point_items"); return 1; } @@ -2836,7 +2836,7 @@ setup_laszip_items( laszip_dll->point_items[i] = (U8*)&(laszip_dll->point.wave_packet); break; default: - sprintf(laszip_dll->error, "unknown LASitem type %d", (I32)laszip->items[i].type); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "unknown LASitem type %d", (I32)laszip->items[i].type); return 1; } } @@ -2847,7 +2847,7 @@ setup_laszip_items( { if (!laszip->setup(point_type, point_size, LASZIP_COMPRESSOR_LAYERED_CHUNKED)) { - sprintf(laszip_dll->error, "cannot compress point_type %d with point_size %d using native", (I32)point_type, (I32)point_size); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot compress point_type %d with point_size %d using native", (I32)point_type, (I32)point_size); return 1; } } @@ -2855,7 +2855,7 @@ setup_laszip_items( { if (!laszip->setup(point_type, point_size, LASZIP_COMPRESSOR_DEFAULT)) { - sprintf(laszip_dll->error, "cannot compress point_type %d with point_size %d", (I32)point_type, (I32)point_size); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot compress point_type %d with point_size %d", (I32)point_type, (I32)point_size); return 1; } } @@ -2870,7 +2870,7 @@ setup_laszip_items( { if (!laszip->set_chunk_size(laszip_dll->set_chunk_size)) { - sprintf(laszip_dll->error, "setting chunk size %d has failed", laszip_dll->set_chunk_size); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "setting chunk size %d has failed", laszip_dll->set_chunk_size); return 1; } } @@ -2897,19 +2897,19 @@ laszip_open_writer( { if (file_name == 0) { - sprintf(laszip_dll->error, "laszip_CHAR pointer 'file_name' is zero"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "laszip_CHAR pointer 'file_name' is zero"); return 1; } if (laszip_dll->reader) { - sprintf(laszip_dll->error, "reader is already open"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reader is already open"); return 1; } if (laszip_dll->writer) { - sprintf(laszip_dll->error, "writer is already open"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writer is already open"); return 1; } @@ -2925,13 +2925,13 @@ laszip_open_writer( if (laszip_dll->file == 0) { - sprintf(laszip_dll->error, "cannot open file '%s'", file_name); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot open file '%s'", file_name); return 1; } if (setvbuf(laszip_dll->file, NULL, _IOFBF, 262144) != 0) { - sprintf(laszip_dll->warning, "setvbuf() failed with buffer size 262144\n"); + snprintf(laszip_dll->warning, sizeof(laszip_dll->warning), "setvbuf() failed with buffer size 262144\n"); } // create the outstream @@ -2943,7 +2943,7 @@ laszip_open_writer( if (laszip_dll->streamout == 0) { - sprintf(laszip_dll->error, "could not alloc ByteStreamOutFile"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "could not alloc ByteStreamOutFile"); return 1; } @@ -3012,7 +3012,7 @@ laszip_open_writer( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_open_writer '%s'", file_name); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_open_writer '%s'", file_name); return 1; } @@ -3038,7 +3038,7 @@ laszip_write_point( // make sure legacy flags and extended flags are identical if ((laszip_dll->point.extended_classification_flags & 0x7) != ((((U8*)&(laszip_dll->point.intensity))[3]) >> 5)) { - sprintf(laszip_dll->error, "legacy flags and extended flags are not identical"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "legacy flags and extended flags are not identical"); return 1; } @@ -3047,7 +3047,7 @@ laszip_write_point( { if (laszip_dll->point.classification != laszip_dll->point.extended_classification) { - sprintf(laszip_dll->error, "legacy classification %d and extended classification %d are not consistent", laszip_dll->point.classification, laszip_dll->point.extended_classification); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "legacy classification %d and extended classification %d are not consistent", laszip_dll->point.classification, laszip_dll->point.extended_classification); return 1; } } @@ -3134,9 +3134,9 @@ laszip_write_point( if (!laszip_dll->writer->write(laszip_dll->point_items)) { #ifdef _WIN32 - sprintf(laszip_dll->error, "writing point %I64d of %I64d total points", laszip_dll->p_count, laszip_dll->npoints); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing point %I64d of %I64d total points", laszip_dll->p_count, laszip_dll->npoints); #else - sprintf(laszip_dll->error, "writing point %lld of %lld total points", laszip_dll->p_count, laszip_dll->npoints); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing point %lld of %lld total points", laszip_dll->p_count, laszip_dll->npoints); #endif return 1; } @@ -3145,7 +3145,7 @@ laszip_write_point( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_write_point"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_write_point"); return 1; } @@ -3168,9 +3168,9 @@ laszip_write_indexed_point( if (!laszip_dll->writer->write(laszip_dll->point_items)) { #ifdef _WIN32 - sprintf(laszip_dll->error, "writing point %I64d of %I64d total points", laszip_dll->p_count, laszip_dll->npoints); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing point %I64d of %I64d total points", laszip_dll->p_count, laszip_dll->npoints); #else - sprintf(laszip_dll->error, "writing point %lld of %lld total points", laszip_dll->p_count, laszip_dll->npoints); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing point %lld of %lld total points", laszip_dll->p_count, laszip_dll->npoints); #endif return 1; } @@ -3182,7 +3182,7 @@ laszip_write_indexed_point( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_write_indexed_point"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_write_indexed_point"); return 1; } @@ -3210,7 +3210,7 @@ laszip_update_inventory( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_update_inventory"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_update_inventory"); return 1; } @@ -3231,13 +3231,13 @@ laszip_close_writer( { if (laszip_dll->writer == 0) { - sprintf(laszip_dll->error, "closing writer before it was opened"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "closing writer before it was opened"); return 1; } if (!laszip_dll->writer->done()) { - sprintf(laszip_dll->error, "done of LASwritePoint failed"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "done of LASwritePoint failed"); return 1; } @@ -3256,14 +3256,14 @@ laszip_close_writer( laszip_dll->streamout->seek(107); if (!laszip_dll->streamout->put32bitsLE((const U8*)&(laszip_dll->inventory->number_of_point_records))) { - sprintf(laszip_dll->error, "updating laszip_dll->inventory->number_of_point_records"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "updating laszip_dll->inventory->number_of_point_records"); return 1; } for (I32 i = 0; i < 5; i++) { if (!laszip_dll->streamout->put32bitsLE((const U8*)&(laszip_dll->inventory->number_of_points_by_return[i+1]))) { - sprintf(laszip_dll->error, "updating laszip_dll->inventory->number_of_points_by_return[%d]\n", i); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "updating laszip_dll->inventory->number_of_points_by_return[%d]\n", i); return 1; } } @@ -3273,37 +3273,37 @@ laszip_close_writer( value = laszip_dll->header.x_scale_factor*laszip_dll->inventory->max_X+laszip_dll->header.x_offset; if (!laszip_dll->streamout->put64bitsLE((const U8*)&value)) { - sprintf(laszip_dll->error, "updating laszip_dll->inventory->max_X"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "updating laszip_dll->inventory->max_X"); return 1; } value = laszip_dll->header.x_scale_factor*laszip_dll->inventory->min_X+laszip_dll->header.x_offset; if (!laszip_dll->streamout->put64bitsLE((const U8*)&value)) { - sprintf(laszip_dll->error, "updating laszip_dll->inventory->min_X"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "updating laszip_dll->inventory->min_X"); return 1; } value = laszip_dll->header.y_scale_factor*laszip_dll->inventory->max_Y+laszip_dll->header.y_offset; if (!laszip_dll->streamout->put64bitsLE((const U8*)&value)) { - sprintf(laszip_dll->error, "updating laszip_dll->inventory->max_Y"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "updating laszip_dll->inventory->max_Y"); return 1; } value = laszip_dll->header.y_scale_factor*laszip_dll->inventory->min_Y+laszip_dll->header.y_offset; if (!laszip_dll->streamout->put64bitsLE((const U8*)&value)) { - sprintf(laszip_dll->error, "updating laszip_dll->inventory->min_Y"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "updating laszip_dll->inventory->min_Y"); return 1; } value = laszip_dll->header.z_scale_factor*laszip_dll->inventory->max_Z+laszip_dll->header.z_offset; if (!laszip_dll->streamout->put64bitsLE((const U8*)&value)) { - sprintf(laszip_dll->error, "updating laszip_dll->inventory->max_Z"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "updating laszip_dll->inventory->max_Z"); return 1; } value = laszip_dll->header.z_scale_factor*laszip_dll->inventory->min_Z+laszip_dll->header.z_offset; if (!laszip_dll->streamout->put64bitsLE((const U8*)&value)) { - sprintf(laszip_dll->error, "updating laszip_dll->inventory->min_Z"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "updating laszip_dll->inventory->min_Z"); return 1; } if (laszip_dll->header.version_minor >= 4) // only update extended counters for LAS 1.4 @@ -3312,7 +3312,7 @@ laszip_close_writer( I64 number = laszip_dll->inventory->number_of_point_records; if (!laszip_dll->streamout->put64bitsLE((const U8*)&number)) { - sprintf(laszip_dll->error, "updating laszip_dll->inventory->extended_number_of_point_records"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "updating laszip_dll->inventory->extended_number_of_point_records"); return 1; } for (I32 i = 0; i < 15; i++) @@ -3320,7 +3320,7 @@ laszip_close_writer( number = laszip_dll->inventory->number_of_points_by_return[i+1]; if (!laszip_dll->streamout->put64bitsLE((const U8*)&number)) { - sprintf(laszip_dll->error, "updating laszip_dll->inventory->extended_number_of_points_by_return[%d]\n", i); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "updating laszip_dll->inventory->extended_number_of_points_by_return[%d]\n", i); return 1; } } @@ -3337,7 +3337,7 @@ laszip_close_writer( if (!laszip_dll->lax_index->write(laszip_dll->lax_file_name)) { - sprintf(laszip_dll->error, "writing LAX file to '%s'", laszip_dll->lax_file_name); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writing LAX file to '%s'", laszip_dll->lax_file_name); return 1; } @@ -3359,7 +3359,7 @@ laszip_close_writer( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_writer_close"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_writer_close"); return 1; } @@ -3381,13 +3381,13 @@ laszip_exploit_spatial_index( { if (laszip_dll->reader) { - sprintf(laszip_dll->error, "reader is already open"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reader is already open"); return 1; } if (laszip_dll->writer) { - sprintf(laszip_dll->error, "writer is already open"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writer is already open"); return 1; } @@ -3395,7 +3395,7 @@ laszip_exploit_spatial_index( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_exploit_spatial_index"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_exploit_spatial_index"); return 1; } @@ -3417,13 +3417,13 @@ laszip_decompress_selective( { if (laszip_dll->reader) { - sprintf(laszip_dll->error, "reader is already open"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reader is already open"); return 1; } if (laszip_dll->writer) { - sprintf(laszip_dll->error, "writer is already open"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writer is already open"); return 1; } @@ -3431,7 +3431,7 @@ laszip_decompress_selective( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_decompress_selective"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_decompress_selective"); return 1; } @@ -3453,170 +3453,170 @@ laszip_read_header( CHAR file_signature[5]; try { laszip_dll->streamin->getBytes((U8*)file_signature, 4); } catch(...) { - sprintf(laszip_dll->error, "reading header.file_signature"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.file_signature"); return 1; } if (strncmp(file_signature, "LASF", 4) != 0) { - sprintf(laszip_dll->error, "wrong file_signature. not a LAS/LAZ file."); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "wrong file_signature. not a LAS/LAZ file."); return 1; } try { laszip_dll->streamin->get16bitsLE((U8*)&(laszip_dll->header.file_source_ID)); } catch(...) { - sprintf(laszip_dll->error, "reading header.file_source_ID"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.file_source_ID"); return 1; } try { laszip_dll->streamin->get16bitsLE((U8*)&(laszip_dll->header.global_encoding)); } catch(...) { - sprintf(laszip_dll->error, "reading header.global_encoding"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.global_encoding"); return 1; } try { laszip_dll->streamin->get32bitsLE((U8*)&(laszip_dll->header.project_ID_GUID_data_1)); } catch(...) { - sprintf(laszip_dll->error, "reading header.project_ID_GUID_data_1"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.project_ID_GUID_data_1"); return 1; } try { laszip_dll->streamin->get16bitsLE((U8*)&(laszip_dll->header.project_ID_GUID_data_2)); } catch(...) { - sprintf(laszip_dll->error, "reading header.project_ID_GUID_data_2"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.project_ID_GUID_data_2"); return 1; } try { laszip_dll->streamin->get16bitsLE((U8*)&(laszip_dll->header.project_ID_GUID_data_3)); } catch(...) { - sprintf(laszip_dll->error, "reading header.project_ID_GUID_data_3"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.project_ID_GUID_data_3"); return 1; } try { laszip_dll->streamin->getBytes((U8*)laszip_dll->header.project_ID_GUID_data_4, 8); } catch(...) { - sprintf(laszip_dll->error, "reading header.project_ID_GUID_data_4"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.project_ID_GUID_data_4"); return 1; } try { laszip_dll->streamin->getBytes((U8*)&(laszip_dll->header.version_major), 1); } catch(...) { - sprintf(laszip_dll->error, "reading header.version_major"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.version_major"); return 1; } try { laszip_dll->streamin->getBytes((U8*)&(laszip_dll->header.version_minor), 1); } catch(...) { - sprintf(laszip_dll->error, "reading header.version_minor"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.version_minor"); return 1; } try { laszip_dll->streamin->getBytes((U8*)laszip_dll->header.system_identifier, 32); } catch(...) { - sprintf(laszip_dll->error, "reading header.system_identifier"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.system_identifier"); return 1; } try { laszip_dll->streamin->getBytes((U8*)laszip_dll->header.generating_software, 32); } catch(...) { - sprintf(laszip_dll->error, "reading header.generating_software"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.generating_software"); return 1; } try { laszip_dll->streamin->get16bitsLE((U8*)&(laszip_dll->header.file_creation_day)); } catch(...) { - sprintf(laszip_dll->error, "reading header.file_creation_day"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.file_creation_day"); return 1; } try { laszip_dll->streamin->get16bitsLE((U8*)&(laszip_dll->header.file_creation_year)); } catch(...) { - sprintf(laszip_dll->error, "reading header.file_creation_year"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.file_creation_year"); return 1; } try { laszip_dll->streamin->get16bitsLE((U8*)&(laszip_dll->header.header_size)); } catch(...) { - sprintf(laszip_dll->error, "reading header.header_size"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.header_size"); return 1; } try { laszip_dll->streamin->get32bitsLE((U8*)&(laszip_dll->header.offset_to_point_data)); } catch(...) { - sprintf(laszip_dll->error, "reading header.offset_to_point_data"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.offset_to_point_data"); return 1; } try { laszip_dll->streamin->get32bitsLE((U8*)&(laszip_dll->header.number_of_variable_length_records)); } catch(...) { - sprintf(laszip_dll->error, "reading header.number_of_variable_length_records"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.number_of_variable_length_records"); return 1; } try { laszip_dll->streamin->getBytes((U8*)&(laszip_dll->header.point_data_format), 1); } catch(...) { - sprintf(laszip_dll->error, "reading header.point_data_format"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.point_data_format"); return 1; } try { laszip_dll->streamin->get16bitsLE((U8*)&(laszip_dll->header.point_data_record_length)); } catch(...) { - sprintf(laszip_dll->error, "reading header.point_data_record_length"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.point_data_record_length"); return 1; } try { laszip_dll->streamin->get32bitsLE((U8*)&(laszip_dll->header.number_of_point_records)); } catch(...) { - sprintf(laszip_dll->error, "reading header.number_of_point_records"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.number_of_point_records"); return 1; } for (i = 0; i < 5; i++) { try { laszip_dll->streamin->get32bitsLE((U8*)&(laszip_dll->header.number_of_points_by_return[i])); } catch(...) { - sprintf(laszip_dll->error, "reading header.number_of_points_by_return %d", i); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.number_of_points_by_return %d", i); return 1; } } try { laszip_dll->streamin->get64bitsLE((U8*)&(laszip_dll->header.x_scale_factor)); } catch(...) { - sprintf(laszip_dll->error, "reading header.x_scale_factor"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.x_scale_factor"); return 1; } try { laszip_dll->streamin->get64bitsLE((U8*)&(laszip_dll->header.y_scale_factor)); } catch(...) { - sprintf(laszip_dll->error, "reading header.y_scale_factor"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.y_scale_factor"); return 1; } try { laszip_dll->streamin->get64bitsLE((U8*)&(laszip_dll->header.z_scale_factor)); } catch(...) { - sprintf(laszip_dll->error, "reading header.z_scale_factor"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.z_scale_factor"); return 1; } try { laszip_dll->streamin->get64bitsLE((U8*)&(laszip_dll->header.x_offset)); } catch(...) { - sprintf(laszip_dll->error, "reading header.x_offset"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.x_offset"); return 1; } try { laszip_dll->streamin->get64bitsLE((U8*)&(laszip_dll->header.y_offset)); } catch(...) { - sprintf(laszip_dll->error, "reading header.y_offset"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.y_offset"); return 1; } try { laszip_dll->streamin->get64bitsLE((U8*)&(laszip_dll->header.z_offset)); } catch(...) { - sprintf(laszip_dll->error, "reading header.z_offset"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.z_offset"); return 1; } try { laszip_dll->streamin->get64bitsLE((U8*)&(laszip_dll->header.max_x)); } catch(...) { - sprintf(laszip_dll->error, "reading header.max_x"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.max_x"); return 1; } try { laszip_dll->streamin->get64bitsLE((U8*)&(laszip_dll->header.min_x)); } catch(...) { - sprintf(laszip_dll->error, "reading header.min_x"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.min_x"); return 1; } try { laszip_dll->streamin->get64bitsLE((U8*)&(laszip_dll->header.max_y)); } catch(...) { - sprintf(laszip_dll->error, "reading header.max_y"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.max_y"); return 1; } try { laszip_dll->streamin->get64bitsLE((U8*)&(laszip_dll->header.min_y)); } catch(...) { - sprintf(laszip_dll->error, "reading header.min_y"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.min_y"); return 1; } try { laszip_dll->streamin->get64bitsLE((U8*)&(laszip_dll->header.max_z)); } catch(...) { - sprintf(laszip_dll->error, "reading header.max_z"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.max_z"); return 1; } try { laszip_dll->streamin->get64bitsLE((U8*)&(laszip_dll->header.min_z)); } catch(...) { - sprintf(laszip_dll->error, "reading header.min_z"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.min_z"); return 1; } @@ -3625,14 +3625,14 @@ laszip_read_header( { if (laszip_dll->header.header_size < 235) { - sprintf(laszip_dll->error, "for LAS 1.%d header_size should at least be 235 but it is only %d", laszip_dll->header.version_minor, laszip_dll->header.header_size); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "for LAS 1.%d header_size should at least be 235 but it is only %d", laszip_dll->header.version_minor, laszip_dll->header.header_size); return 1; } else { try { laszip_dll->streamin->get64bitsLE((U8*)&(laszip_dll->header.start_of_waveform_data_packet_record)); } catch(...) { - sprintf(laszip_dll->error, "reading header.start_of_waveform_data_packet_record"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.start_of_waveform_data_packet_record"); return 1; } laszip_dll->header.user_data_in_header_size = laszip_dll->header.header_size - 235; @@ -3648,31 +3648,31 @@ laszip_read_header( { if (laszip_dll->header.header_size < 375) { - sprintf(laszip_dll->error, "for LAS 1.%d header_size should at least be 375 but it is only %d", laszip_dll->header.version_minor, laszip_dll->header.header_size); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "for LAS 1.%d header_size should at least be 375 but it is only %d", laszip_dll->header.version_minor, laszip_dll->header.header_size); return 1; } else { try { laszip_dll->streamin->get64bitsLE((U8*)&(laszip_dll->header.start_of_first_extended_variable_length_record)); } catch(...) { - sprintf(laszip_dll->error, "reading header.start_of_first_extended_variable_length_record"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.start_of_first_extended_variable_length_record"); return 1; } try { laszip_dll->streamin->get32bitsLE((U8*)&(laszip_dll->header.number_of_extended_variable_length_records)); } catch(...) { - sprintf(laszip_dll->error, "reading header.number_of_extended_variable_length_records"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.number_of_extended_variable_length_records"); return 1; } try { laszip_dll->streamin->get64bitsLE((U8*)&(laszip_dll->header.extended_number_of_point_records)); } catch(...) { - sprintf(laszip_dll->error, "reading header.extended_number_of_point_records"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.extended_number_of_point_records"); return 1; } for (i = 0; i < 15; i++) { try { laszip_dll->streamin->get64bitsLE((U8*)&(laszip_dll->header.extended_number_of_points_by_return[i])); } catch(...) { - sprintf(laszip_dll->error, "reading header.extended_number_of_points_by_return[%d]", i); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.extended_number_of_points_by_return[%d]", i); return 1; } } @@ -3691,7 +3691,7 @@ laszip_read_header( try { laszip_dll->streamin->getBytes((U8*)laszip_dll->header.user_data_in_header, laszip_dll->header.user_data_in_header_size); } catch(...) { - sprintf(laszip_dll->error, "reading %u bytes of data into header.user_data_in_header", laszip_dll->header.user_data_in_header_size); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading %u bytes of data into header.user_data_in_header", laszip_dll->header.user_data_in_header_size); return 1; } } @@ -3709,7 +3709,7 @@ laszip_read_header( if (laszip_dll->header.vlrs == 0) { - sprintf(laszip_dll->error, "allocating %u VLRs", laszip_dll->header.number_of_variable_length_records); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "allocating %u VLRs", laszip_dll->header.number_of_variable_length_records); return 1; } @@ -3719,7 +3719,7 @@ laszip_read_header( if (((int)laszip_dll->header.offset_to_point_data - vlrs_size - laszip_dll->header.header_size) < 54) { - sprintf(laszip_dll->warning, "only %d bytes until point block after reading %d of %d vlrs. skipping remaining vlrs ...", (int)laszip_dll->header.offset_to_point_data - vlrs_size - laszip_dll->header.header_size, i, laszip_dll->header.number_of_variable_length_records); + snprintf(laszip_dll->warning, sizeof(laszip_dll->warning), "only %d bytes until point block after reading %d of %d vlrs. skipping remaining vlrs ...", (int)laszip_dll->header.offset_to_point_data - vlrs_size - laszip_dll->header.header_size, i, laszip_dll->header.number_of_variable_length_records); laszip_dll->header.number_of_variable_length_records = i; break; } @@ -3728,28 +3728,28 @@ laszip_read_header( try { laszip_dll->streamin->get16bitsLE((U8*)&(laszip_dll->header.vlrs[i].reserved)); } catch(...) { - sprintf(laszip_dll->error, "reading header.vlrs[%u].reserved", i); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.vlrs[%u].reserved", i); return 1; } try { laszip_dll->streamin->getBytes((U8*)laszip_dll->header.vlrs[i].user_id, 16); } catch(...) { - sprintf(laszip_dll->error, "reading header.vlrs[%u].user_id", i); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.vlrs[%u].user_id", i); return 1; } try { laszip_dll->streamin->get16bitsLE((U8*)&(laszip_dll->header.vlrs[i].record_id)); } catch(...) { - sprintf(laszip_dll->error, "reading header.vlrs[%u].record_id", i); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.vlrs[%u].record_id", i); return 1; } try { laszip_dll->streamin->get16bitsLE((U8*)&(laszip_dll->header.vlrs[i].record_length_after_header)); } catch(...) { - sprintf(laszip_dll->error, "reading header.vlrs[%u].record_length_after_header", i); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.vlrs[%u].record_length_after_header", i); return 1; } try { laszip_dll->streamin->getBytes((U8*)laszip_dll->header.vlrs[i].description, 32); } catch(...) { - sprintf(laszip_dll->error, "reading header.vlrs[%u].description", i); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading header.vlrs[%u].description", i); return 1; } @@ -3761,14 +3761,14 @@ laszip_read_header( if ((laszip_dll->header.vlrs[i].reserved != 0xAABB) && (laszip_dll->header.vlrs[i].reserved != 0x0)) { - sprintf(laszip_dll->warning,"wrong header.vlrs[%d].reserved: %d != 0xAABB and %d != 0x0", i, laszip_dll->header.vlrs[i].reserved, laszip_dll->header.vlrs[i].reserved); + snprintf(laszip_dll->warning, sizeof(laszip_dll->warning),"wrong header.vlrs[%d].reserved: %d != 0xAABB and %d != 0x0", i, laszip_dll->header.vlrs[i].reserved, laszip_dll->header.vlrs[i].reserved); } // make sure there are enough bytes left to read the data of the variable length record before the point block starts if (((int)laszip_dll->header.offset_to_point_data - vlrs_size - laszip_dll->header.header_size) < laszip_dll->header.vlrs[i].record_length_after_header) { - sprintf(laszip_dll->warning, "only %d bytes until point block when trying to read %d bytes into header.vlrs[%d].data", (int)laszip_dll->header.offset_to_point_data - vlrs_size - laszip_dll->header.header_size, laszip_dll->header.vlrs[i].record_length_after_header, i); + snprintf(laszip_dll->warning, sizeof(laszip_dll->warning), "only %d bytes until point block when trying to read %d bytes into header.vlrs[%d].data", (int)laszip_dll->header.offset_to_point_data - vlrs_size - laszip_dll->header.header_size, laszip_dll->header.vlrs[i].record_length_after_header, i); laszip_dll->header.vlrs[i].record_length_after_header = (int)laszip_dll->header.offset_to_point_data - vlrs_size - laszip_dll->header.header_size; } @@ -3787,7 +3787,7 @@ laszip_read_header( if (laszip == 0) { - sprintf(laszip_dll->error, "could not alloc LASzip"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "could not alloc LASzip"); return 1; } @@ -3810,52 +3810,52 @@ laszip_read_header( try { laszip_dll->streamin->get16bitsLE((U8*)&(laszip->compressor)); } catch(...) { - sprintf(laszip_dll->error, "reading compressor %d", (I32)laszip->compressor); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading compressor %d", (I32)laszip->compressor); return 1; } try { laszip_dll->streamin->get16bitsLE((U8*)&(laszip->coder)); } catch(...) { - sprintf(laszip_dll->error, "reading coder %d", (I32)laszip->coder); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading coder %d", (I32)laszip->coder); return 1; } try { laszip_dll->streamin->getBytes((U8*)&(laszip->version_major), 1); } catch(...) { - sprintf(laszip_dll->error, "reading version_major %d", (I32)laszip->version_major); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading version_major %d", (I32)laszip->version_major); return 1; } try { laszip_dll->streamin->getBytes((U8*)&(laszip->version_minor), 1); } catch(...) { - sprintf(laszip_dll->error, "reading version_minor %d", (I32)laszip->version_minor); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading version_minor %d", (I32)laszip->version_minor); return 1; } try { laszip_dll->streamin->get16bitsLE((U8*)&(laszip->version_revision)); } catch(...) { - sprintf(laszip_dll->error, "reading version_revision %d", (I32)laszip->version_revision); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading version_revision %d", (I32)laszip->version_revision); return 1; } try { laszip_dll->streamin->get32bitsLE((U8*)&(laszip->options)); } catch(...) { - sprintf(laszip_dll->error, "reading options %u", laszip->options); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading options %u", laszip->options); return 1; } try { laszip_dll->streamin->get32bitsLE((U8*)&(laszip->chunk_size)); } catch(...) { - sprintf(laszip_dll->error, "reading chunk_size %u", laszip->chunk_size); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading chunk_size %u", laszip->chunk_size); return 1; } try { laszip_dll->streamin->get64bitsLE((U8*)&(laszip->number_of_special_evlrs)); } catch(...) { - sprintf(laszip_dll->error, "reading number_of_special_evlrs %d", (I32)laszip->number_of_special_evlrs); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading number_of_special_evlrs %d", (I32)laszip->number_of_special_evlrs); return 1; } try { laszip_dll->streamin->get64bitsLE((U8*)&(laszip->offset_to_special_evlrs)); } catch(...) { - sprintf(laszip_dll->error, "reading offset_to_special_evlrs %d", (I32)laszip->offset_to_special_evlrs); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading offset_to_special_evlrs %d", (I32)laszip->offset_to_special_evlrs); return 1; } try { laszip_dll->streamin->get16bitsLE((U8*)&(laszip->num_items)); } catch(...) { - sprintf(laszip_dll->error, "reading num_items %d", (I32)laszip->num_items); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading num_items %d", (I32)laszip->num_items); return 1; } laszip->items = new LASitem[laszip->num_items]; @@ -3865,18 +3865,18 @@ laszip_read_header( U16 type; try { laszip_dll->streamin->get16bitsLE((U8*)&type); } catch(...) { - sprintf(laszip_dll->error, "reading type of item %u", j); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading type of item %u", j); return 1; } laszip->items[j].type = (LASitem::Type)type; try { laszip_dll->streamin->get16bitsLE((U8*)&(laszip->items[j].size)); } catch(...) { - sprintf(laszip_dll->error, "reading size of item %u", j); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading size of item %u", j); return 1; } try { laszip_dll->streamin->get16bitsLE((U8*)&(laszip->items[j].version)); } catch(...) { - sprintf(laszip_dll->error, "reading version of item %u", j); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading version of item %u", j); return 1; } } @@ -3887,7 +3887,7 @@ laszip_read_header( try { laszip_dll->streamin->getBytes(laszip_dll->header.vlrs[i].data, laszip_dll->header.vlrs[i].record_length_after_header); } catch(...) { - sprintf(laszip_dll->error, "reading %d bytes of data into header.vlrs[%u].data", (I32)laszip_dll->header.vlrs[i].record_length_after_header, i); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading %d bytes of data into header.vlrs[%u].data", (I32)laszip_dll->header.vlrs[i].record_length_after_header, i); return 1; } } @@ -3937,7 +3937,7 @@ laszip_read_header( try { laszip_dll->streamin->getBytes((U8*)laszip_dll->header.user_data_after_header, laszip_dll->header.user_data_after_header_size); } catch(...) { - sprintf(laszip_dll->error, "reading %u bytes of data into header.user_data_after_header", laszip_dll->header.user_data_after_header_size); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading %u bytes of data into header.user_data_after_header", laszip_dll->header.user_data_after_header_size); return 1; } } @@ -3948,7 +3948,7 @@ laszip_read_header( { if (!laszip) { - sprintf(laszip_dll->error, "this file was compressed with an experimental version of LASzip. contact 'martin.isenburg@rapidlasso.com' for assistance"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "this file was compressed with an experimental version of LASzip. contact 'martin.isenburg@rapidlasso.com' for assistance"); return 1; } laszip_dll->header.point_data_format &= 127; @@ -3962,7 +3962,7 @@ laszip_read_header( *is_compressed = 1; if (!laszip->check(laszip_dll->header.point_data_record_length)) { - sprintf(laszip_dll->error, "%s upgrade to the latest release of LASzip or contact 'martin.isenburg@rapidlasso.com' for assistance", laszip->get_error()); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "%s upgrade to the latest release of LASzip or contact 'martin.isenburg@rapidlasso.com' for assistance", laszip->get_error()); return 1; } } @@ -3973,12 +3973,12 @@ laszip_read_header( laszip = new LASzip; if (laszip == 0) { - sprintf(laszip_dll->error, "could not alloc LASzip"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "could not alloc LASzip"); return 1; } if (!laszip->setup(laszip_dll->header.point_data_format, laszip_dll->header.point_data_record_length, LASZIP_COMPRESSOR_NONE)) { - sprintf(laszip_dll->error, "invalid combination of point_data_format %d and point_data_record_length %d", (I32)laszip_dll->header.point_data_format, (I32)laszip_dll->header.point_data_record_length); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "invalid combination of point_data_format %d and point_data_record_length %d", (I32)laszip_dll->header.point_data_format, (I32)laszip_dll->header.point_data_record_length); return 1; } } @@ -3994,7 +3994,7 @@ laszip_read_header( if (laszip_dll->point_items == 0) { - sprintf(laszip_dll->error, "could not alloc point_items"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "could not alloc point_items"); return 1; } @@ -4026,7 +4026,7 @@ laszip_read_header( laszip_dll->point_items[i] = (U8*)&(laszip_dll->point.wave_packet); break; default: - sprintf(laszip_dll->error, "unknown LASitem type %d", (I32)laszip->items[i].type); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "unknown LASitem type %d", (I32)laszip->items[i].type); return 1; } } @@ -4155,7 +4155,7 @@ laszip_read_header( if (laszip_remove_vlr(laszip_dll, "lascompatible\0\0", 22204)) { - sprintf(laszip_dll->error, "removing the compatibility VLR"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "removing the compatibility VLR"); return 1; } @@ -4173,7 +4173,7 @@ laszip_read_header( { if (laszip_add_vlr(laszip_dll, "LASF_Spec\0\0\0\0\0\0", 4, (laszip_U16)(attributer.number_attributes*sizeof(LASattribute)), 0, (laszip_U8*)attributer.attributes)) { - sprintf(laszip_dll->error, "rewriting the extra bytes VLR without 'LAS 1.4 compatibility mode' attributes"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "rewriting the extra bytes VLR without 'LAS 1.4 compatibility mode' attributes"); return 1; } } @@ -4181,7 +4181,7 @@ laszip_read_header( { if (laszip_remove_vlr(laszip_dll, "LASF_Spec\0\0\0\0\0\0", 4)) { - sprintf(laszip_dll->error, "removing the LAS 1.4 attribute VLR"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "removing the LAS 1.4 attribute VLR"); return 1; } } @@ -4264,19 +4264,19 @@ laszip_read_header( laszip_dll->reader = new LASreadPoint(laszip_dll->las14_decompress_selective); if (laszip_dll->reader == 0) { - sprintf(laszip_dll->error, "could not alloc LASreadPoint"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "could not alloc LASreadPoint"); return 1; } if (!laszip_dll->reader->setup(laszip->num_items, laszip->items, laszip)) { - sprintf(laszip_dll->error, "setup of LASreadPoint failed"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "setup of LASreadPoint failed"); return 1; } if (!laszip_dll->reader->init(laszip_dll->streamin)) { - sprintf(laszip_dll->error, "init of LASreadPoint failed"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "init of LASreadPoint failed"); return 1; } @@ -4306,25 +4306,25 @@ laszip_open_reader( { if (file_name == 0) { - sprintf(laszip_dll->error, "laszip_CHAR pointer 'file_name' is zero"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "laszip_CHAR pointer 'file_name' is zero"); return 1; } if (is_compressed == 0) { - sprintf(laszip_dll->error, "laszip_BOOL pointer 'is_compressed' is zero"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "laszip_BOOL pointer 'is_compressed' is zero"); return 1; } if (laszip_dll->writer) { - sprintf(laszip_dll->error, "writer is already open"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writer is already open"); return 1; } if (laszip_dll->reader) { - sprintf(laszip_dll->error, "reader is already open"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reader is already open"); return 1; } @@ -4340,13 +4340,13 @@ laszip_open_reader( if (laszip_dll->file == 0) { - sprintf(laszip_dll->error, "cannot open file '%s'", file_name); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "cannot open file '%s'", file_name); return 1; } if (setvbuf(laszip_dll->file, NULL, _IOFBF, 262144) != 0) { - sprintf(laszip_dll->warning, "setvbuf() failed with buffer size 262144\n"); + snprintf(laszip_dll->warning, sizeof(laszip_dll->warning), "setvbuf() failed with buffer size 262144\n"); } if (IS_LITTLE_ENDIAN()) @@ -4356,7 +4356,7 @@ laszip_open_reader( if (laszip_dll->streamin == 0) { - sprintf(laszip_dll->error, "could not alloc ByteStreamInFile"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "could not alloc ByteStreamInFile"); return 1; } @@ -4382,7 +4382,7 @@ laszip_open_reader( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_open_reader"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_open_reader"); return 1; } @@ -4405,25 +4405,25 @@ laszip_has_spatial_index( { if (is_indexed == 0) { - sprintf(laszip_dll->error, "laszip_BOOL pointer 'is_indexed' is zero"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "laszip_BOOL pointer 'is_indexed' is zero"); return 1; } if (laszip_dll->reader == 0) { - sprintf(laszip_dll->error, "reader is not open"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reader is not open"); return 1; } if (laszip_dll->writer) { - sprintf(laszip_dll->error, "writer is already open"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writer is already open"); return 1; } if (laszip_dll->lax_exploit == 0) { - sprintf(laszip_dll->error, "exploiting of spatial indexing not enabled before opening reader"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "exploiting of spatial indexing not enabled before opening reader"); return 1; } @@ -4448,7 +4448,7 @@ laszip_has_spatial_index( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_have_spatial_index"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_have_spatial_index"); return 1; } @@ -4474,19 +4474,19 @@ laszip_inside_rectangle( { if (laszip_dll->reader == 0) { - sprintf(laszip_dll->error, "reader is not open"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reader is not open"); return 1; } if (is_empty == 0) { - sprintf(laszip_dll->error, "laszip_BOOL pointer 'is_empty' is zero"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "laszip_BOOL pointer 'is_empty' is zero"); return 1; } if (laszip_dll->lax_exploit == FALSE) { - sprintf(laszip_dll->error, "exploiting of spatial indexing not enabled before opening reader"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "exploiting of spatial indexing not enabled before opening reader"); return 1; } @@ -4522,7 +4522,7 @@ laszip_inside_rectangle( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_inside_rectangle"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_inside_rectangle"); return 1; } @@ -4546,9 +4546,9 @@ laszip_seek_point( if (!laszip_dll->reader->seek((U32)laszip_dll->p_count, (U32)index)) { #ifdef _WIN32 - sprintf(laszip_dll->error, "seeking from index %I64d to index %I64d for file with %I64d points", laszip_dll->p_count, index, laszip_dll->npoints); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "seeking from index %I64d to index %I64d for file with %I64d points", laszip_dll->p_count, index, laszip_dll->npoints); #else - sprintf(laszip_dll->error, "seeking from index %lld to index %lld for file with %lld points", laszip_dll->p_count, index, laszip_dll->npoints); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "seeking from index %lld to index %lld for file with %lld points", laszip_dll->p_count, index, laszip_dll->npoints); #endif return 1; } @@ -4556,7 +4556,7 @@ laszip_seek_point( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_seek_point"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_seek_point"); return 1; } @@ -4579,9 +4579,9 @@ laszip_read_point( if (!laszip_dll->reader->read(laszip_dll->point_items)) { #ifdef _WIN32 - sprintf(laszip_dll->error, "reading point %I64d of %I64d total points", laszip_dll->p_count, laszip_dll->npoints); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading point %I64d of %I64d total points", laszip_dll->p_count, laszip_dll->npoints); #else - sprintf(laszip_dll->error, "reading point %lld of %lld total points", laszip_dll->p_count, laszip_dll->npoints); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading point %lld of %lld total points", laszip_dll->p_count, laszip_dll->npoints); #endif return 1; } @@ -4631,7 +4631,7 @@ laszip_read_point( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_read_point"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_read_point"); return 1; } @@ -4689,9 +4689,9 @@ laszip_read_inside_point( if (laszip_dll->p_count < laszip_dll->npoints) { #ifdef _WIN32 - sprintf(laszip_dll->error, "reading point %I64d of %I64d total points", laszip_dll->p_count, laszip_dll->npoints); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading point %I64d of %I64d total points", laszip_dll->p_count, laszip_dll->npoints); #else - sprintf(laszip_dll->error, "reading point %lld of %lld total points", laszip_dll->p_count, laszip_dll->npoints); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reading point %lld of %lld total points", laszip_dll->p_count, laszip_dll->npoints); #endif return 1; } @@ -4700,7 +4700,7 @@ laszip_read_inside_point( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_read_inside_point"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_read_inside_point"); return 1; } @@ -4720,13 +4720,13 @@ laszip_close_reader( { if (laszip_dll->reader == 0) { - sprintf(laszip_dll->error, "closing reader before it was opened"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "closing reader before it was opened"); return 1; } if (!laszip_dll->reader->done()) { - sprintf(laszip_dll->error, "done of LASreadPoint failed"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "done of LASreadPoint failed"); return 1; } @@ -4753,7 +4753,7 @@ laszip_close_reader( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_close_reader"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_close_reader"); return 1; } @@ -4778,19 +4778,19 @@ laszip_open_reader_stream( { if (is_compressed == 0) { - sprintf(laszip_dll->error, "laszip_BOOL pointer 'is_compressed' is zero"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "laszip_BOOL pointer 'is_compressed' is zero"); return 1; } if (laszip_dll->writer) { - sprintf(laszip_dll->error, "writer is already open"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writer is already open"); return 1; } if (laszip_dll->reader) { - sprintf(laszip_dll->error, "reader is already open"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reader is already open"); return 1; } @@ -4803,7 +4803,7 @@ laszip_open_reader_stream( if (laszip_dll->streamin == 0) { - sprintf(laszip_dll->error, "could not alloc ByteStreamInIstream"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "could not alloc ByteStreamInIstream"); return 1; } @@ -4811,7 +4811,7 @@ laszip_open_reader_stream( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_open_reader"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_open_reader"); return 1; } } @@ -4836,13 +4836,13 @@ laszip_open_writer_stream( { if (laszip_dll->writer) { - sprintf(laszip_dll->error, "writer is already open"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "writer is already open"); return 1; } if (laszip_dll->reader) { - sprintf(laszip_dll->error, "reader is already open"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "reader is already open"); return 1; } @@ -4855,7 +4855,7 @@ laszip_open_writer_stream( if (laszip_dll->streamout == 0) { - sprintf(laszip_dll->error, "could not alloc ByteStreamOutOstream"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "could not alloc ByteStreamOutOstream"); return 1; } @@ -4914,7 +4914,7 @@ laszip_open_writer_stream( } catch (...) { - sprintf(laszip_dll->error, "internal error in laszip_open_writer_stream."); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "internal error in laszip_open_writer_stream."); return 1; } laszip_dll->error[0] = '\0'; @@ -4949,7 +4949,7 @@ laszip_create_laszip_vlr( if (out == 0) { - sprintf(laszip_dll->error, "could not alloc ByteStreamOutArray"); + snprintf(laszip_dll->error, sizeof(laszip_dll->error), "could not alloc ByteStreamOutArray"); return 1; } diff --git a/PotreeConverter/Converter/libs/laszip/src/laszipper.cpp b/PotreeConverter/Converter/libs/laszip/src/laszipper.cpp index c04cc45..00df85c 100644 --- a/PotreeConverter/Converter/libs/laszip/src/laszipper.cpp +++ b/PotreeConverter/Converter/libs/laszip/src/laszipper.cpp @@ -1,12 +1,12 @@ -/* -=============================================================================== - - FILE: laszipper.cpp - - CONTENTS: - - see corresponding header file - +/* +=============================================================================== + + FILE: laszipper.cpp + + CONTENTS: + + see corresponding header file + PROGRAMMERS: martin.isenburg@rapidlasso.com - http://rapidlasso.com @@ -21,13 +21,13 @@ This software is distributed WITHOUT ANY WARRANTY and without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - - CHANGE HISTORY: - - see corresponding header file - -=============================================================================== -*/ + + CHANGE HISTORY: + + see corresponding header file + +=============================================================================== +*/ #include "laszipper.hpp" #include @@ -103,7 +103,7 @@ bool LASzipper::close() if (!done) return return_error("done() of LASwritePoint failed"); return true; } - + const char* LASzipper::get_error() const { return error_string; @@ -112,22 +112,22 @@ const char* LASzipper::get_error() const bool LASzipper::return_error(const char* error) { char err[256]; - sprintf(err, "%s (LASzip v%d.%dr%d)", error, LASZIP_VERSION_MAJOR, LASZIP_VERSION_MINOR, LASZIP_VERSION_REVISION); + snprintf(err, sizeof(err), "%s (LASzip v%d.%dr%d)", error, LASZIP_VERSION_MAJOR, LASZIP_VERSION_MINOR, LASZIP_VERSION_REVISION); if (error_string) free(error_string); error_string = LASCopyString(err); return false; } -LASzipper::LASzipper() +LASzipper::LASzipper() { - error_string = 0; - count = 0; - stream = 0; - writer = 0; -} - -LASzipper::~LASzipper() + error_string = 0; + count = 0; + stream = 0; + writer = 0; +} + +LASzipper::~LASzipper() { if (error_string) free(error_string); - if (writer || stream) close(); -} + if (writer || stream) close(); +} diff --git a/PotreeConverter/Converter/modules/unsuck/cpu.h b/PotreeConverter/Converter/modules/unsuck/cpu.h new file mode 100644 index 0000000..72d734f --- /dev/null +++ b/PotreeConverter/Converter/modules/unsuck/cpu.h @@ -0,0 +1,63 @@ +/* vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap + * + * Copyright 2012 Matthew McCormick + * Copyright 2015 Pawel 'l0ner' Soltys + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CPU_H_ +#define CPU_H_ + +#include + +#if defined(__APPLE__) && defined(__MACH__) + #define CP_USER 0 + #define CP_SYS 1 + #define CP_IDLE 2 + #define CP_NICE 3 + #define CP_STATES 4 +#else + #define CP_USER 0 + #define CP_NICE 1 + #define CP_SYS 2 + + #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) + // *BSD or OSX + #define CP_INTR 3 + #define CP_IDLE 4 + #define CP_STATES 5 + #else + //linux + #define CP_IDLE 3 + #define CP_STATES 4 + #endif +#endif + +float cpu_percentage( unsigned ); +uint32_t get_cpu_count(); + +/** CPU percentage output mode. + * + * Examples: + * + * CPU_MODE_DEFAULT: 100% + * CPU_MODE_THREADS: 800% (8 cores, fully loaded) + */ +enum CPU_MODE +{ + CPU_MODE_DEFAULT, + CPU_MODE_THREADS +}; + +#endif \ No newline at end of file diff --git a/PotreeConverter/Converter/modules/unsuck/memory.h b/PotreeConverter/Converter/modules/unsuck/memory.h new file mode 100644 index 0000000..5e11025 --- /dev/null +++ b/PotreeConverter/Converter/modules/unsuck/memory.h @@ -0,0 +1,56 @@ +/* vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap + * + * Copyright 2012 Matthew McCormick + * Copyright 2015 Pawel 'l0ner' Soltys + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MEMORY_H_ +#define MEMORY_H_ + +#include + +/** Memory status in megabytes */ +struct MemoryStatus +{ + float used_mem; + float total_mem; +}; + +/** Get the current memory status */ +void mem_status( MemoryStatus & status ); + + +/** Memory status string output mode. + * + * Examples: + * + * MEMORY_MODE_DEFAULT: 11156/16003MB + * MEMORY_MODE_FREE_MEMORY: + * MEMORY_MODE_USAGE_PERCENTAGE: + */ +enum MEMORY_MODE +{ + MEMORY_MODE_DEFAULT, + MEMORY_MODE_FREE_MEMORY, + MEMORY_MODE_USAGE_PERCENTAGE +}; + +std::string mem_string( const MemoryStatus & mem_status, + MEMORY_MODE mode = MEMORY_MODE_DEFAULT, + bool use_colors = false, + bool use_powerline_left = false, + bool use_powerline_right = false ); + +#endif diff --git a/PotreeConverter/Converter/modules/unsuck/unsuck.hpp b/PotreeConverter/Converter/modules/unsuck/unsuck.hpp index f114426..f413f70 100644 --- a/PotreeConverter/Converter/modules/unsuck/unsuck.hpp +++ b/PotreeConverter/Converter/modules/unsuck/unsuck.hpp @@ -16,6 +16,9 @@ #include #include +#include "cpu.h" +#include "memory.h" + using std::cout; using std::endl; using std::to_string; @@ -43,6 +46,8 @@ static double Infinity = std::numeric_limits::infinity(); constexpr auto fseek_64_all_platforms = fseeko64; #elif defined(WIN32) constexpr auto fseek_64_all_platforms = _fseeki64; +#elif defined(__APPLE__) +constexpr auto fseek_64_all_platforms = fseeko; #endif @@ -586,4 +591,3 @@ inline string rightPad(string in, int64_t length, const char character = ' ') { #define GENERATE_ERROR_MESSAGE cout << "ERROR(" << __FILE__ << ":" << __LINE__ << "): " #define GENERATE_WARN_MESSAGE cout << "WARNING: " - diff --git a/PotreeConverter/Converter/modules/unsuck/unsuck_platform_specific.cpp b/PotreeConverter/Converter/modules/unsuck/unsuck_platform_specific.cpp index 0fc6b14..537c4cd 100644 --- a/PotreeConverter/Converter/modules/unsuck/unsuck_platform_specific.cpp +++ b/PotreeConverter/Converter/modules/unsuck/unsuck_platform_specific.cpp @@ -356,5 +356,212 @@ CpuData getCpuData() { return data; } +#elif defined(__APPLE__) + +// see https://stackoverflow.com/questions/63166/how-to-determine-cpu-and-memory-consumption-from-inside-a-process + +#include +#include +#include +#include // for sysctl + +#include // usleep() + +enum BYTE_UNITS +{ + BYTES = 0, + KILOBYTES = 1, + MEGABYTES = 2, + GIGABYTES = 3 +}; + +template +inline T convert_unit( T num, int to, int from = BYTES) +{ + for( ; from < to; from++) + { + num /= 1024; + } + return num; +} + +void mem_status(MemoryStatus & status) +{ + // These values are in bytes + u_int64_t total_mem; + float used_mem; + float percentage_mem; + float free_mem; + float free_mem_in_gigabytes; // used to check if free mem < 1 GB + //u_int64_t unused_mem; + + vm_size_t page_size; + vm_statistics_data_t vm_stats; + + // Get total physical memory + int mib[] = { CTL_HW, HW_MEMSIZE }; + size_t length = sizeof( total_mem ); + sysctl( mib, 2, &total_mem, &length, NULL, 0 ); + + mach_port_t mach_port = mach_host_self(); + mach_msg_type_number_t count = sizeof( vm_stats ) / sizeof( natural_t ); + if( KERN_SUCCESS == host_page_size( mach_port, &page_size ) && + KERN_SUCCESS == host_statistics( mach_port, HOST_VM_INFO, + ( host_info_t )&vm_stats, &count ) + ) + { + //unused_mem = static_cast( vm_stats.free_count * page_size ); + + used_mem = static_cast( + ( vm_stats.active_count + vm_stats.wire_count ) * page_size); + } + + status.used_mem = convert_unit(static_cast< float >( used_mem ), BYTES ); + status.total_mem = convert_unit(static_cast< float >( total_mem ), BYTES ); +} + +MemoryData getMemoryData() { + MemoryStatus status; + + mem_status(status); + + MemoryData data; + + { + data.virtual_total = status.total_mem; + data.virtual_used = status.used_mem; + data.physical_total = status.total_mem; + data.physical_used = status.used_mem; + } + + { + data.virtual_usedByProcess = status.used_mem; + data.virtual_usedByProcess_max = status.used_mem; + data.physical_usedByProcess = status.used_mem; + data.physical_usedByProcess_max = status.used_mem; + } + + return data; +} + + +void printMemoryReport() { + + auto memoryData = getMemoryData(); + double vm = double(memoryData.virtual_usedByProcess) / (1024.0 * 1024.0 * 1024.0); + double pm = double(memoryData.physical_usedByProcess) / (1024.0 * 1024.0 * 1024.0); + + stringstream ss; + ss << "memory usage: " + << "virtual: " << formatNumber(vm, 1) << " GB, " + << "physical: " << formatNumber(pm, 1) << " GB" + << endl; + + cout << ss.str(); +} + +void launchMemoryChecker(int64_t maxMB, double checkInterval) { + + auto interval = std::chrono::milliseconds(int64_t(checkInterval * 1000)); + + thread t([maxMB, interval]() { + + static double lastReport = 0.0; + static double reportInterval = 1.0; + static double lastUsage = 0.0; + static double largestUsage = 0.0; + + while (true) { + auto memdata = getMemoryData(); + + using namespace std::chrono_literals; + std::this_thread::sleep_for(interval); + } + + }); + t.detach(); +} + +static int numProcessors; +static bool initialized = false; + +void init() { + numProcessors = std::thread::hardware_concurrency(); + + initialized = true; +} + +uint32_t get_cpu_count() +{ + return sysconf( _SC_NPROCESSORS_ONLN ); +} + +double getCpuUsage(){ + + return cpu_percentage(99000); +} + +host_cpu_load_info_data_t _get_cpu_percentage() +{ + kern_return_t error; + mach_msg_type_number_t count; + host_cpu_load_info_data_t r_load; + mach_port_t mach_port; + + count = HOST_CPU_LOAD_INFO_COUNT; + mach_port = mach_host_self(); + error = host_statistics(mach_port, HOST_CPU_LOAD_INFO, + ( host_info_t )&r_load, &count ); + + if ( error != KERN_SUCCESS ) + { + return host_cpu_load_info_data_t(); + } + + return r_load; +} + +float cpu_percentage( unsigned int cpu_usage_delay ) +{ + // Get the load times from the XNU kernel + host_cpu_load_info_data_t load1 = _get_cpu_percentage(); + usleep( cpu_usage_delay ); + host_cpu_load_info_data_t load2 = _get_cpu_percentage(); + + // Current load times + unsigned long long current_user = load1.cpu_ticks[CP_USER]; + unsigned long long current_system = load1.cpu_ticks[CP_SYS]; + unsigned long long current_nice = load1.cpu_ticks[CP_NICE]; + unsigned long long current_idle = load1.cpu_ticks[CP_IDLE]; + // Next load times + unsigned long long next_user = load2.cpu_ticks[CP_USER]; + unsigned long long next_system = load2.cpu_ticks[CP_SYS]; + unsigned long long next_nice = load2.cpu_ticks[CP_NICE]; + unsigned long long next_idle = load2.cpu_ticks[CP_IDLE]; + // Difference between the two + unsigned long long diff_user = next_user - current_user; + unsigned long long diff_system = next_system - current_system; + unsigned long long diff_nice = next_nice - current_nice; + unsigned long long diff_idle = next_idle - current_idle; + +// return static_cast(diff_user) / static_cast(diff_user + diff_idle) * 100; + + return static_cast( diff_user + diff_system + diff_nice ) / + static_cast( diff_user + diff_system + diff_nice + diff_idle ) * + 100.0; +} + +CpuData getCpuData() { + + if (!initialized) { + init(); + } + + CpuData data; + data.numProcessors = get_cpu_count(); + data.usage = getCpuUsage(); + + return data; +} #endif \ No newline at end of file diff --git a/PotreeConverter/Converter/src/chunker_countsort_laszip.cpp b/PotreeConverter/Converter/src/chunker_countsort_laszip.cpp index 086c00d..22aac74 100644 --- a/PotreeConverter/Converter/src/chunker_countsort_laszip.cpp +++ b/PotreeConverter/Converter/src/chunker_countsort_laszip.cpp @@ -232,9 +232,10 @@ namespace chunker_countsort_laszip { double ux = (double(X) * posScale.x + posOffset.x - min.x) / size.x; double uy = (double(Y) * posScale.y + posOffset.y - min.y) / size.y; double uz = (double(Z) * posScale.z + posOffset.z - min.z) / size.z; - + + double iota = 0.0001; bool inBox = ux >= 0.0 && uy >= 0.0 && uz >= 0.0; - inBox = inBox && ux <= 1.0 && uy <= 1.0 && uz <= 1.0; + inBox = inBox && ux <= 1.0 + iota && uy <= 1.0 + iota && uz <= 1.0 + iota; if (!inBox) { stringstream ss; @@ -242,6 +243,7 @@ namespace chunker_countsort_laszip { ss << "box.min: " << min.toString() << endl; ss << "box.max: " << max.toString() << endl; ss << "point: " << Vector3(x, y, z).toString() << endl; + ss << "uxyz: " << Vector3(ux, uy, uz).toString() << endl; ss << "file: " << path << endl; ss << "PotreeConverter requires a valid bounding box to operate." << endl; ss << "Please try to repair the bounding box, e.g. using lasinfo with the -repair_bb argument." << endl; diff --git a/PotreeConverter/Converter/src/main.cpp b/PotreeConverter/Converter/src/main.cpp index 9d14d49..5ddf459 100644 --- a/PotreeConverter/Converter/src/main.cpp +++ b/PotreeConverter/Converter/src/main.cpp @@ -180,8 +180,13 @@ Curated curateSources(vector paths) { sources.reserve(paths.size()); mutex mtx; + +#if defined(__APPLE__) + for_each(paths.begin(), paths.end(), [&mtx, &sources](string path) { +#else auto parallel = std::execution::par; for_each(parallel, paths.begin(), paths.end(), [&mtx, &sources](string path) { +#endif auto header = loadLasHeader(path); auto filesize = fs::file_size(path); diff --git a/PotreeConverter/README.md b/PotreeConverter/README.md index 75da73c..83f4c9c 100644 --- a/PotreeConverter/README.md +++ b/PotreeConverter/README.md @@ -19,6 +19,8 @@ Altough the converter made a major step to version 2.0, the format it produces i # Getting Started +**IMPORTANT** Mac usage info not 100% accurate. The word accurate should probably not even be mentioned, but it works. + 1. Download windows binaries or * Download source code * Install [CMake](https://cmake.org/) 3.16 or later @@ -31,7 +33,7 @@ Altough the converter made a major step to version 2.0, the format it produces i ``` cmake ../ ``` - * On linux, run: ```make``` + * On linux/mac, run: ```make``` * On windows, open Visual Studio 2019 Project ./Converter/Converter.sln and compile it in release mode 2. run ```PotreeConverter.exe -o ``` * Optionally specify the sampling strategy: diff --git a/README.MD b/README.MD index 5390f3d..e51ef30 100644 --- a/README.MD +++ b/README.MD @@ -9,6 +9,8 @@ The main steps are: `./PotreeConverter` converts LAS files into Potree's Octree Structure, which the Molloy Explorer Potree Viewer supports as its native input format. Additional documentation on the PotreeConverter can be found in the PotreeConverter GitHub repository: [PotreeConverter](https://github.com/potree/PotreeConverter) +We used this specific fork of the PotreeConverter to deal with a compatibility issue the original repo had with MacOS. [PotreeConverter Fork](https://github.com/LeftOfHere/PotreeConverter/) + ## Requirements ### Prerequisites