From 6e9d496ab3e970ef68c730fb3673b40fcdd6812d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 31 Oct 2019 14:06:34 +0100 Subject: [PATCH] ValueFlow: handling of char literal size before ValueType has been set --- lib/valueflow.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index c8c60c77c..84ffeba27 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1004,7 +1004,20 @@ static Token * valueFlowSetConstantValue(Token *tok, const Settings *settings, b setTokenValue(const_cast(tok->next()), value, settings); } } else if (tok2->tokType() == Token::eChar) { - size_t sz = ValueFlow::getSizeOf(*tok2->valueType(), settings); + nonneg int sz = 0; + if (cpp && settings->standards.cpp >= Standards::CPP20 && tok2->isUtf8()) + sz = 1; + else if (tok2->isUtf16()) + sz = 2; + else if (tok2->isUtf32()) + sz = 4; + else if (tok2->isLong()) + sz = settings->sizeof_wchar_t; + else if ((tok2->isCChar() && !cpp) || (tok2->isCMultiChar())) + sz = settings->sizeof_int; + else + sz = 1; + if (sz > 0) { ValueFlow::Value value(sz); value.setKnown();