Merge branch 'fix-formatted-read-into-char-buf-1.6' into 'stable-1.6'

Backport from 1.7: Use str.read() to read into char *.

See merge request etherlab.org/ethercat!211
This commit is contained in:
Florian Pose
2026-08-11 16:04:53 +02:00
5 changed files with 23 additions and 20 deletions
+2
View File
@@ -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
+5 -5
View File
@@ -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());
+3 -3
View File
@@ -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());
+8 -8
View File
@@ -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.
*
@@ -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 <alias>" << endl
@@ -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());
+5 -4
View File
@@ -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
{