Skip to content

Commit

Permalink
Fix integer overflow (1 << (' ' - 1))
Browse files Browse the repository at this point in the history
On platforms where integer by default is int32(max is 2147483647) and
(1 << (' ' - 1)) will be 2147483648

Change-Id: I790d33bd4e473925d6897dd87cbffdfe8dd7938f
Reviewed-by: Thiago Macieira <[email protected]>
Reviewed-by: Edward Welbourne <[email protected]>
  • Loading branch information
msvetkin committed Apr 10, 2018
1 parent 4160315 commit 28f9b35
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/corelib/tools/qlocale_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,15 @@ QString qt_readEscapedFormatString(QStringView format, int *idx);
bool qt_splitLocaleName(const QString &name, QString &lang, QString &script, QString &cntry);
int qt_repeatCount(QStringView s);

enum { AsciiSpaceMask = (1 << (' ' - 1)) |
(1 << ('\t' - 1)) | // 9: HT - horizontal tab
(1 << ('\n' - 1)) | // 10: LF - line feed
(1 << ('\v' - 1)) | // 11: VT - vertical tab
(1 << ('\f' - 1)) | // 12: FF - form feed
(1 << ('\r' - 1)) }; // 13: CR - carriage return
enum { AsciiSpaceMask = (1u << (' ' - 1)) |
(1u << ('\t' - 1)) | // 9: HT - horizontal tab
(1u << ('\n' - 1)) | // 10: LF - line feed
(1u << ('\v' - 1)) | // 11: VT - vertical tab
(1u << ('\f' - 1)) | // 12: FF - form feed
(1u << ('\r' - 1)) }; // 13: CR - carriage return
Q_DECL_CONSTEXPR inline bool ascii_isspace(uchar c)
{
return c >= 1U && c <= 32U && (uint(AsciiSpaceMask) >> uint(c - 1)) & 1U;
return c >= 1u && c <= 32u && (AsciiSpaceMask >> uint(c - 1)) & 1u;
}

#if defined(Q_COMPILER_CONSTEXPR)
Expand Down

0 comments on commit 28f9b35

Please sign in to comment.