Skip to content

Commit 2ec7bf6

Browse files
Fixed ics.SpyMessage.ExtraDataPtr can't handle larger than 255 length (#215)
Issue #214
1 parent 8ebac5c commit 2ec7bf6

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/methods.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5518,7 +5518,6 @@ PyObject* meth_get_component_versions(PyObject* self, PyObject* args) // icsneoG
55185518
char buffer[512];
55195519
return set_ics_exception(exception_runtime_error(), dll_get_error(buffer));
55205520
}
5521-
uint64_t imei = 0;
55225521
ice::Function<int __stdcall(void*, VersionReport*, uint64_t*, bool)> icsneoGetComponentVersions(lib, "icsneoGetComponentVersions");
55235522
auto gil = PyAllowThreads();
55245523
std::vector<VersionReport> version_reports;
@@ -5534,7 +5533,7 @@ PyObject* meth_get_component_versions(PyObject* self, PyObject* args) // icsneoG
55345533
if (!tuple) {
55355534
return NULL;
55365535
}
5537-
for (int i = 0; i < length; ++i) {
5536+
for (uint64_t i = 0; i < length; ++i) {
55385537
PyObject* obj = _getPythonModuleObject("ics.structures.version_report", "version_report");
55395538
if (!obj) {
55405539
return set_ics_exception(exception_runtime_error(), "Failed to allocate version_report");

src/object_spy_message.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ static int spy_message_object_setattr(PyObject* o, PyObject* name, PyObject* val
142142
if (!data && !PyLong_Check(data)) {
143143
obj->msg.AckBytes[i] = 0;
144144
} else {
145-
obj->msg.AckBytes[i] = (unsigned char)PyLong_AsLong(data);
145+
obj->msg.AckBytes[i] = static_cast<uint8_t>(PyLong_AsLong(data));
146146
}
147147
}
148148
return 0;
@@ -163,8 +163,8 @@ static int spy_message_object_setattr(PyObject* o, PyObject* name, PyObject* val
163163
} else {
164164
((spy_message_j1850_object*)obj)->msg.Header[i] = (unsigned char)PyLong_AsLong(data);
165165
}
166-
obj->msg.NumberBytesHeader = static_cast<uint8_t>(PyObject_Length(value));
167166
}
167+
obj->msg.NumberBytesHeader = static_cast<uint8_t>(PyObject_Length(value));
168168
return 0;
169169
} else if (PyUnicode_CompareWithASCIIString(name, "Protocol") == 0) {
170170
// Ethernet behavior is backward to CAN and will crash if enabled.
@@ -181,7 +181,7 @@ static int spy_message_object_setattr(PyObject* o, PyObject* name, PyObject* val
181181
return -1;
182182
}
183183
// Get tuple items and place them in array, set as 0 if error.
184-
size_t length = static_cast<uint8_t>(PyObject_Length(value));
184+
size_t length = static_cast<uint16_t>(PyObject_Length(value));
185185
if (obj->msg.ExtraDataPtr != NULL)
186186
delete[] (unsigned char*)obj->msg.ExtraDataPtr;
187187
obj->msg.ExtraDataPtr = new unsigned char[length];

0 commit comments

Comments
 (0)