@@ -97,9 +97,9 @@ const ValueFlow::Value* ProgramMemory::getValue(nonneg int exprid, bool impossib
9797}
9898
9999// cppcheck-suppress unusedFunction
100- bool ProgramMemory::getIntValue (nonneg int exprid, MathLib::bigint& result) const
100+ bool ProgramMemory::getIntValue (nonneg int exprid, MathLib::bigint& result, bool impossible ) const
101101{
102- const ValueFlow::Value* value = getValue (exprid);
102+ const ValueFlow::Value* value = getValue (exprid, impossible );
103103 if (value && value->isIntValue ()) {
104104 result = value->intvalue ;
105105 return true ;
@@ -115,9 +115,9 @@ void ProgramMemory::setIntValue(const Token* expr, MathLib::bigint value, bool i
115115 setValue (expr, v);
116116}
117117
118- bool ProgramMemory::getTokValue (nonneg int exprid, const Token*& result) const
118+ bool ProgramMemory::getTokValue (nonneg int exprid, const Token*& result, bool impossible ) const
119119{
120- const ValueFlow::Value* value = getValue (exprid);
120+ const ValueFlow::Value* value = getValue (exprid, impossible );
121121 if (value && value->isTokValue ()) {
122122 result = value->tokvalue ;
123123 return true ;
@@ -126,18 +126,18 @@ bool ProgramMemory::getTokValue(nonneg int exprid, const Token*& result) const
126126}
127127
128128// cppcheck-suppress unusedFunction
129- bool ProgramMemory::getContainerSizeValue (nonneg int exprid, MathLib::bigint& result) const
129+ bool ProgramMemory::getContainerSizeValue (nonneg int exprid, MathLib::bigint& result, bool impossible ) const
130130{
131- const ValueFlow::Value* value = getValue (exprid);
131+ const ValueFlow::Value* value = getValue (exprid, impossible );
132132 if (value && value->isContainerSizeValue ()) {
133133 result = value->intvalue ;
134134 return true ;
135135 }
136136 return false ;
137137}
138- bool ProgramMemory::getContainerEmptyValue (nonneg int exprid, MathLib::bigint& result) const
138+ bool ProgramMemory::getContainerEmptyValue (nonneg int exprid, MathLib::bigint& result, bool impossible ) const
139139{
140- const ValueFlow::Value* value = getValue (exprid, true );
140+ const ValueFlow::Value* value = getValue (exprid, impossible );
141141 if (value && value->isContainerSizeValue ()) {
142142 if (value->isImpossible () && value->intvalue == 0 ) {
143143 result = false ;
@@ -166,25 +166,25 @@ void ProgramMemory::setUnknown(const Token* expr) {
166166 (*mValues )[expr].valueType = ValueFlow::Value::ValueType::UNINIT;
167167}
168168
169- bool ProgramMemory::hasValue (nonneg int exprid) const
169+ bool ProgramMemory::hasValue (nonneg int exprid, bool impossible ) const
170170{
171171 const auto it = find (exprid);
172- return it != mValues ->cend ();
172+ return it != mValues ->cend () && (impossible || !it-> second . isImpossible ()) ;
173173}
174174
175- const ValueFlow::Value& ProgramMemory::at (nonneg int exprid) const {
175+ const ValueFlow::Value& ProgramMemory::at (nonneg int exprid, bool impossible ) const {
176176 const auto it = find (exprid);
177- if (it == mValues ->cend ()) {
177+ if (it == mValues ->cend () && (impossible || !it-> second . isImpossible ()) ) {
178178 throw std::out_of_range (" ProgramMemory::at" );
179179 }
180180 return it->second ;
181181}
182182
183- ValueFlow::Value& ProgramMemory::at (nonneg int exprid) {
183+ ValueFlow::Value& ProgramMemory::at (nonneg int exprid, bool impossible ) {
184184 copyOnWrite ();
185185
186186 const auto it = find (exprid);
187- if (it == mValues ->end ()) {
187+ if (it == mValues ->end () && (impossible || !it-> second . isImpossible ()) ) {
188188 throw std::out_of_range (" ProgramMemory::at" );
189189 }
190190 return it->second ;
0 commit comments