From ae2cf49ede942344fbb2d5a0b58fc8a9409cb911 Mon Sep 17 00:00:00 2001 From: Florian Pose Date: Tue, 11 Aug 2026 14:32:51 +0200 Subject: [PATCH 1/2] Backport from 1.7: Use str.read() to read into char *. --- tool/CommandDownload.cpp | 10 +++++----- tool/CommandRegWrite.cpp | 6 +++--- tool/CommandSoeWrite.cpp | 8 ++++---- tool/DataTypeHandler.cpp | 9 +++++---- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/tool/CommandDownload.cpp b/tool/CommandDownload.cpp index 4daeb7dd..6fe64de1 100644 --- a/tool/CommandDownload.cpp +++ b/tool/CommandDownload.cpp @@ -1,6 +1,6 @@ /***************************************************************************** * - * Copyright (C) 2006-2022 Florian Pose, Ingenieurgemeinschaft IgH + * Copyright (C) 2006-2026 Florian Pose, Ingenieurgemeinschaft IgH * * This file is part of the IgH EtherCAT Master. * @@ -168,8 +168,8 @@ void CommandDownload::execute(const StringVector &args) data.data = new uint8_t[data.data_size + 1]; try { - data.data_size = interpretAsType( - dataType, contents, data.data, data.data_size); + data.data_size = interpretAsType(dataType, contents, data.data, + data.data_size + 1); } catch (SizeException &e) { delete [] data.data; throwCommandException(e.what()); @@ -189,8 +189,8 @@ void CommandDownload::execute(const StringVector &args) data.data = new uint8_t[data.data_size + 1]; try { - data.data_size = interpretAsType( - dataType, args[valueIndex], data.data, data.data_size); + data.data_size = interpretAsType(dataType, args[valueIndex], + data.data, data.data_size + 1); } catch (SizeException &e) { delete [] data.data; throwCommandException(e.what()); diff --git a/tool/CommandRegWrite.cpp b/tool/CommandRegWrite.cpp index 5a1e9d5c..441ce7d7 100644 --- a/tool/CommandRegWrite.cpp +++ b/tool/CommandRegWrite.cpp @@ -1,6 +1,6 @@ /***************************************************************************** * - * Copyright (C) 2006-2012 Florian Pose, Ingenieurgemeinschaft IgH + * Copyright (C) 2006-2026 Florian Pose, Ingenieurgemeinschaft IgH * * This file is part of the IgH EtherCAT Master. * @@ -121,11 +121,11 @@ void CommandRegWrite::execute(const StringVector &args) io.size = 1024; // FIXME } - io.data = new uint8_t[io.size]; + io.data = new uint8_t[io.size + 1]; try { io.size = interpretAsType( - dataType, args[1], io.data, io.size); + dataType, args[1], io.data, io.size + 1); } catch (SizeException &e) { delete [] io.data; throwCommandException(e.what()); diff --git a/tool/CommandSoeWrite.cpp b/tool/CommandSoeWrite.cpp index a227d470..0b234030 100644 --- a/tool/CommandSoeWrite.cpp +++ b/tool/CommandSoeWrite.cpp @@ -1,6 +1,6 @@ /***************************************************************************** * - * Copyright (C) 2006-2009 Florian Pose, Ingenieurgemeinschaft IgH + * Copyright (C) 2006-2026 Florian Pose, Ingenieurgemeinschaft IgH * * This file is part of the IgH EtherCAT Master. * @@ -143,18 +143,18 @@ void CommandSoeWrite::execute(const StringVector &args) memSize = dataType->byteSize; } else { // guess string type size - memSize = args[valueArgIndex].size() + 1; + memSize = args[valueArgIndex].size(); if (!memSize) { err << "Empty argument not allowed."; throwInvalidUsageException(err); } } - ioctl.data = new uint8_t[memSize]; + ioctl.data = new uint8_t[memSize + 1]; try { ioctl.data_size = interpretAsType( - dataType, args[valueArgIndex], ioctl.data, memSize); + dataType, args[valueArgIndex], ioctl.data, memSize + 1); } catch (SizeException &e) { delete [] ioctl.data; throwCommandException(e.what()); diff --git a/tool/DataTypeHandler.cpp b/tool/DataTypeHandler.cpp index 9f0ebc62..f61f9b7d 100644 --- a/tool/DataTypeHandler.cpp +++ b/tool/DataTypeHandler.cpp @@ -1,6 +1,6 @@ /***************************************************************************** * - * Copyright (C) 2006-2022 Florian Pose, Ingenieurgemeinschaft IgH + * Copyright (C) 2006-2026 Florian Pose, Ingenieurgemeinschaft IgH * * This file is part of the IgH EtherCAT Master. * @@ -178,13 +178,14 @@ size_t DataTypeHandler::interpretAsType( case 0x000a: // octet_string case 0x000b: // unicode_string dataSize = str.str().size(); - if (dataSize > targetSize) { + if (dataSize + 1 > targetSize) { // leave room for terminating \0 stringstream err; err << "String too large (" - << dataSize << " > " << targetSize << ")"; + << dataSize << " > " << targetSize - 1 << ")"; throw SizeException(err.str()); } - str >> (char *) target; + str.read((char *) target, dataSize); + ((char *) target)[dataSize] = 0; // terminating \0 break; case 0x0011: // double { From 827129d7076c9f5367186b38b014ebcbe96004ee Mon Sep 17 00:00:00 2001 From: Florian Pose Date: Tue, 11 Aug 2026 15:55:24 +0200 Subject: [PATCH 2/2] Fixed cpplint warnings. --- CPPLINT.cfg | 2 ++ tool/CommandSoeWrite.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CPPLINT.cfg b/CPPLINT.cfg index 9ff7e021..60656277 100644 --- a/CPPLINT.cfg +++ b/CPPLINT.cfg @@ -1,7 +1,9 @@ filter=-build/header_guard filter=-build/include_subdir filter=-build/include_what_you_use +filter=-build/namespaces filter=-readability/braces +filter=-readability/casting filter=-readability/multiline_comment filter=-runtime/int filter=-runtime/printf diff --git a/tool/CommandSoeWrite.cpp b/tool/CommandSoeWrite.cpp index 0b234030..df280843 100644 --- a/tool/CommandSoeWrite.cpp +++ b/tool/CommandSoeWrite.cpp @@ -58,11 +58,11 @@ string CommandSoeWrite::helpString(const string &binaryBaseName) const << " Bit 11 - 0: Data block number" << endl << " or a string like 'P-0-150'." << endl << " VALUE is the value to write (see below)." << endl - << endl - << "The VALUE argument is interpreted as the given data type" << endl - << "(--type is mandatory) and written to the selected slave." << endl << endl - << typeInfo() + << "The VALUE argument is interpreted as the given data type" << endl + << "(--type is mandatory) and written to the selected slave." << endl + << endl + << typeInfo() << endl << "Command-specific options:" << endl << " --alias -a " << endl