Handle signal and slot argument count mismatch
The source and replica can disagree about the number of arguments for
a signal or a slot. Previously, the received arguments were used
regardless of their count. If too few arguments arrived, the code read
past the end of the argument list, which caused undefined behavior and
crashes. If too many arguments arrived, the extra ones were silently
dropped.
Check the argument count before calling a slot on the source side or
emitting a signal on the replica side.
The new check revealed a bug in the Source implementation - it
incorrectly truncated the list with the signal arguments, and as a
result could actually send more arguments than needed, sending some
stale arguments. Fix it by simply calling QList::resize() instead of
a hand-rolled loop with QList::removeLast().
This pre-existing bug, however, means that we need to allow the
replica implementation to accept more signal arguments than it
expects. This is fine, because we can simply ignore extra arguments.
For the signals with less arguments and for slots with argument
count mismatch the new code will print a warning and skip the calls.
A source notify signal without arguments is still accepted, because
the replica then reads the value from the property.
The new tests use a repc-generated replica and a QObject-based source
whose slots and signals receive both more and fewer arguments than
they expect. This includes a source signal without any arguments,
which goes through a separate code path on the replica side. The tests
were crashing without the fixes.
Task-number: QTBUG-150775
Pick-to: 6.12 6.8 6.5 5.15
Change-Id: I8e7c0f3b882fb4bf5478a6eac2bd6528c2041156
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>