<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/106023>106023</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Static Analyzer Fails to Detect WRAPPER_ESCAPE Issues in Code Analysis
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
zxyzxy1111
</td>
</tr>
</table>
<pre>
**Background:**
While analyzing the code,I have discovered that these codes may have WRAPPER_ESCAPE issues, but clang-tidy is unable to detect them.
**Issue 1:**
The known error code is located at: `opencv/3rdparty/openexr/IlmImf/ImfDwaCompressor.cpp
The error function code is as follows:



Specifically, this error reports that the internal representation of the local variable `tmpHalfBuffer` is transferred to `this->_rowPtrs[chan][y]` in the `Imf_opencv::DwaCompressor::LossyDctEncoderBase::execute` function, but it is destroyed when exiting the scope. This situation may lead to undefined behavior or program crashes.
**Usage of the local variable `tmpHalfBuffer`:**
- At line 1388, the condition `tmpHalfBufferElements` is true.
- At line 1389, `operator[]` is called, extracting the wrapped state of the local variable `tmpHalfBuffer` and assigning it to `tmpHalfBufferPtr`.
**Continuing the Loop:**
- At line 1397, the condition `chan < this->_rowPtrs.size()` is true.
- At line 1399, the condition `this->_type[chan] != Imf_opencv::FLOAT` is true, continuing the loop.
**Nested Loop:**
- At line 1402, the condition `y < this->_height` is true.
- At line 1408, the condition `x < this->_width` is true.
These conditional judgments and loops appear multiple times in the code, indicating that the code iterates multiple times when processing the width and height of the image.
**Main Issue:**
- At line 1428, the internal representation of the local variable `tmpHalfBuffer` is transferred to `this->_rowPtrs[chan][y]`, but it is destroyed when exiting the scope. This means that the contents of `tmpHalfBuffer` will be destroyed when the function exits, but its reference is still stored in `this->_rowPtrs[chan][y]`, which may lead to undefined behavior or program crashes.
**Issue 2:**
`ogre/RenderSystems/GLSupport/src/GLSL/OgreGLSLShaderCommon.cpp

- Line 96: `src` is assigned to `mSource.c_str()`, at this point `src` points to the internal data of `mSource`.
- Line 103: `mSource` is reassigned to `String(out, out_size)`, which may cause the internal data of `mSource` to be reallocated or modified.
- Line 104: `if (out < src || out > src + src_len)`, at this point `src` may already point to invalid memory because the internal data of `mSource` has been modified.
**Summary:**
The internal representation of `this->mSource` is used after being invalidated, leading to potential undefined behavior. This belongs to WRAPPER-ESCAPE.
- Line: 101
- Description: End of the `if` statement.
- Calling `operator=` invalidates the internal representation of `this->mSource`.
- Line: 103
- Description: Calling `operator=` invalidates the internal representation of `this->mSource`.
- Line: 104
- Description: Using the invalidated internal representation of `this->mSource`.
**Thoughts:**
Are the error reports correct? Why did the clang-tidy WRAPPER_ESCAPE related rules not report any errors? Where is the problem? How should it be resolved?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEWMtu47jSfhp6U5AhUfJFCy-ci_8JkP9M0MmglwFFlizOUKRAUnHcT39ASo4v7cn0zGmcs4kViqz6quqrC8Wck1uNuCKzGzK7m7DeN8auvr3vv73vsyzLJpUR-xWha0LXN4z_sbWm14Lk62GJpHckXX9tpEJgmqn9N6m34BsEbgQSevsADXtDENJx84YWBfiG-bDDDXsctGw_bPr6Zf30dP_l9f75dv10D9K5Hh2ht1D1Hrhiept4KfYgHfSaVQrBGxDokUeB7XRAMyB7CKchu0D60iD8oc1OA1prbEQQ5CnDmUcBzJN8DWSemg41fyN0k1vRMev3hG7CGr5bQjcPqn1o6_DQ1nc7dmvazqJzxk551x01DTrqXnMvjf5QxhzURimzcwHdiDkjsxvZsi2S2R2hy8b7Lr6mG0I3W-mbvppy0xK66R3ahHnPeNOi9o7QDXMO48OCYZZxzJMa6Swp6lmVsKrOkiznWBSsyLDmhJY_WWkp0iytFknFl5gUAllS1dU8KXgl5osS82VJf7rSKkvLTBSzJBVZkRRVtkyWHEVSZPlsNl-IOc_qo9L497lDLmvJmVL7QCvfSDfGyGJnrHcf5ASpPVrNVHhj0aH2LMbQ1PF14IuCN2Zl5CGZp77t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