Fix and simplify QString::mid
authorJoão Abecasis <joao.abecasis@nokia.com>
Mon, 13 Feb 2012 23:02:08 +0000 (00:02 +0100)
committerQt by Nokia <qt-info@nokia.com>
Tue, 14 Feb 2012 11:50:14 +0000 (12:50 +0100)
commit75286739de854d761bbfcababa50d1bc6dfda12a
treeb9ccc90c3209fe61e7c5f5d3b90a0847d330d67b
parentf9872d12a6fb81aa0efa995720c7d733bbbdd71b
Fix and simplify QString::mid

'position' was being used to initialize 'n' before being fully
validated. To compensate for this, the code attempted to fix 'n' once
'position' was found to be invalid (negative). This would, however, also
attempt to "fix" a perfectly valid value of 'n'.

By fully validating 'position' beforehand we avoid this trap and can
safely use it to validate and reset 'n', as needed.

Arithmetic for boundary conditions of 'n' was rearranged to avoid
triggering integer overflow.

Removed explicit check for shared_null, as the same behaviour can be
supported without it.

Change-Id: Ie9bff7b8137a74f55c7dcfe629bd569045e28f3c
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
src/corelib/tools/qstring.cpp
tests/auto/corelib/tools/qstring/tst_qstring.cpp