fix: ensuring no segfault when c library function returns oversized string#1794
fix: ensuring no segfault when c library function returns oversized string#1794Angus-Bethke-Bachmann wants to merge 7 commits into
Conversation
Build Artifacts🐧 Linux
From workflow run 🪟 Windows
From workflow run |
|
|
||
| node_type.is_sized_string() | ||
| } | ||
| _ => { |
There was a problem hiding this comment.
The logic in this match arm seems like it duplicates the _ arm of is_output_assignment_and_type_cast_needed. Can we extract this into a function and use them in all applicable predicates here?
There was a problem hiding this comment.
With more changes to address the above these have diverged far enough apart that this is no longer necessary. But I'm happy to spend more time trying to streamline this file if you'd like?
mhasel
left a comment
There was a problem hiding this comment.
Previous comments have all been addressed, however a regression slipped in with the guessing heuristic approach
| } | ||
| } | ||
|
|
||
| let declared_index_with_return_slot = declared_index + 1; |
There was a problem hiding this comment.
Instead of this guessing heuristic, can't we thread the correct index through here? I think the lowerer should deterministically know it (either aggregates or fn-pointers, right?)
I think this also caused a regression where it now scans if there is a VAR_OUTPUT either left or right, which can cause mis-fires on arguments that are not VAR_OUTPUTs at all. If you have an aggregate VAR_INPUT that is larger than a neighboring VAR_OUTPUT, it will get a temp variable instead, leading to incorrect behaviour.
Regression example:
FUNCTION Config_GetString : DINT
VAR_INPUT Key : STRING[1023]; END_VAR
VAR_OUTPUT Value : STRING[28]; END_VAR
Value := 'hi';
END_FUNCTION
PROGRAM mainProg
VAR keyVar : STRING[10]; outVar : STRING[28]; r : DINT; END_VAR
keyVar := 'my-key';
r := Config_GetString(keyVar, outVar);
PRINTF('key=[%s]$N', keyVar); // will print 'key=[]', `keyVar` passed to VAR_INPUT `Key` was replaced by a temp
END_PROGRAM
FUNCTION main
mainProg();
END_FUNCTION
There was a problem hiding this comment.
Yeah... that was a terrible idea 😞 I've switch it to look at the annotation instead to get the correct parameter index. Only snag was that the lowerer could sometimes change the parameter indexes if a new parameter was inserted, so I added an explicit flag for that. This should cover all the bases (for now anyway).
Changed
Testing
clibrary case