Avoid -Wstringop-overread by using a view with encoded length

For some reason the suppression stopped working for me, but using the
viewAt function is better in general as it doesn't depend on null
termination.

Amends da84941375d8301d9f22df1fa3753571de005c64 (viewAt() was added by
2c2c6de85ae41d09063f3c68a42522e3d74ad8fa for 6.3, so we can use it in
all affected branches).

Pick-to: 6.8 6.7 6.5
Change-Id: Ic71bd559929a2cd0cdea4ed1cc1edcfc583865ff
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Allan Sandfeld Jensen 2024-10-02 11:36:55 +02:00 committed by Marc Mutz
parent dee05596d3
commit cec64aaf2a

View File

@ -35,7 +35,7 @@ static constexpr auto magicRuleTypes = qOffsetStringArray(
QMimeMagicRule::Type QMimeMagicRule::type(const QByteArray &theTypeName)
{
for (int i = String; i <= Byte; ++i) {
if (theTypeName == magicRuleTypes.at(i))
if (theTypeName == magicRuleTypes.viewAt(i))
return Type(i);
}
return Invalid;