Closed psychon closed 1 year ago
LGTM. Could you provide a PR, please?
LGTM.
Which of the two proposed variants do you mean? Or are both fine?
Could you provide a PR, please?
Sorry, nope, I cannot. I would gladly provide a LGPL licensed patch, but you do not accept such contributions. In fact, I fear that if I actually work too much on this, the license would actually prevent anyone else from doing the work in a way that you would deem acceptable (because that would then easily end up as a derived work of my patch and that makes license stuff more complicated).
I choose the proposal with 2 mallocs, way easier to understand and maintain ;) Thank you @psychon
Thanks!
Hi!
libmodbus version
Sure, but I am not using any version:
OS and/or distribution
Environment
Since you apparently want to know my architecture, here's my CPU:
Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
Description
The "protocol independent" TCP code uses this struct:
https://github.com/stephane/libmodbus/blob/3da2d01916ef118aba30a1951d89e0ca0f90e2f7/src/modbus-tcp-private.h#L30-L42
This has arbitrary length limits of 1024 bytes of the node length and 31 bytes for the service.
Also, this allocates more than 1 KiB of memory even when I just provide 10 characters. That is 99% wasted memory for storing two short strings.
The implementation returns an error if these limits are reached:
https://github.com/stephane/libmodbus/blob/3da2d01916ef118aba30a1951d89e0ca0f90e2f7/src/modbus-tcp.c#L896-L897
https://github.com/stephane/libmodbus/blob/3da2d01916ef118aba30a1951d89e0ca0f90e2f7/src/modbus-tcp.c#L919-L920
Expected behaviour
Less memory usage and no arbitrary limits.
Actual behaviour
This section doesn't really fit this report, so I will instead use this for suggestions.
I see two ways for this:
If you do not like the two extra memory allocations:
My other idea would be to use flexible array members. This means something like that (patch also completely untested):
Steps to reproduce the behavior (commands or source code)
Source code is linked above, I guess. I don't have any own code using libmodbus, so....?
libmodbus output with debug mode enabled
Uhm...
command not found
, I guess? Seepkg-config
output from above.Copyright
If you do not worry about copyright issues with my untested sketch patches above, then just ignore this section.
In case you worry: Pick one of the following: