diff options
author | Denis Shienkov <denis.shienkov@gmail.com> | 2015-10-02 17:00:47 +0300 |
---|---|---|
committer | Denis Shienkov <denis.shienkov@gmail.com> | 2015-10-07 08:59:37 +0000 |
commit | 23fa484265ce7b6fe02d2891da38debebf176d3d (patch) | |
tree | fdd58e4f2f7c63bf285e5927617f81ebcafd52fb /src/serialport/qserialport_win_p.h | |
parent | 570e93fed299cff645deebe0f4a5df8ea5864206 (diff) | |
download | qtserialport-23fa484265ce7b6fe02d2891da38debebf176d3d.tar.gz |
Refactor QSPI code on Windows
Current approach with passing of the array's data pointer to a
Win API functions when the array is empty has potential danger.
Because the data pointer is invalid, and if a Win API function
tries to get access to this pointer then this can cause a crash
or an UB. Still this does not happens, but nobody guarantees
that this will be same in future.
It is better to pre-allocate the array with some size (e.g. with
the MAX_PATH size). In this case we can pass the data pointer
without any problem.
Besides, the Win API functions will return result with the first
pass if the array size is sufficient; otherwise it returns
ERROR_MORE_DATA error code and we can re-allocate the array with
required size and to return a result in the second pass.
We re-allocate the array with size more than required on some
bytes with filling of the array with zeros. This allows us to
convert it using QString::fromWCharArray() without specifying a
size, and to remove the toStringAndTrimNullCharacter() function.
(cherry-picked from 96b9590dbeb20e000d9d9308bee2162b1101a7e0)
Change-Id: I5976485286db4097514ea7b3a8adfc9a6a7cea4f
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Diffstat (limited to 'src/serialport/qserialport_win_p.h')
0 files changed, 0 insertions, 0 deletions