<blockquote style="border-left: 1px solid #aaa; margin: 10px 0; padding: 0 10px;"><p style="white-space: pre-wrap; word-wrap: break-word;">Patch Set 1:</p><p style="white-space: pre-wrap; word-wrap: break-word;">Maybe, change like this instead should work (a simple reorder of checks in existing code):</p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">AST_INLINE_API(<br>void ast_copy_string(char *dst, const char *src, size_t size),<br>{<br>        while (size && *src) {<br>                *dst++ = *src++;<br>              size--;<br>       }<br>     if (__builtin_expect(!size, 0))<br>               dst--;<br>        *dst = '\0';<br>}<br>)</pre></blockquote><p style="white-space: pre-wrap; word-wrap: break-word;">You cannot set anything in the buffer if the size is zero.  The caller has told us there is no size to the passed in buffer so there is no room for the string terminator.  The code I have posted will prevent the unnecessary buffer read valgrind found because the code will not copy the string terminator that may or may not be there.  The code I posted is simpler.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/14626">View Change</a></p><ul style="list-style: none; padding: 0;"></ul><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/14626">change 14626</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/14626"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Ib4a75cffeb1eb8cf01136ef30306bd623e531a2a </div>
<div style="display:none"> Gerrit-Change-Number: 14626 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Nickolay V. Shmyrev <nshmyrev@alphacephei.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-Comment-Date: Sun, 05 Jul 2020 14:05:52 +0000 </div>
<div style="display:none"> Gerrit-HasComments: No </div>
<div style="display:none"> Gerrit-Has-Labels: No </div>
<div style="display:none"> Gerrit-MessageType: comment </div>