<blockquote style="border-left: 1px solid #aaa; margin: 10px 0; padding: 0 10px;"><p style="white-space: pre-wrap; word-wrap: break-word;">I'm not a big fan of such over-optimization patches.</p></blockquote><p style="white-space: pre-wrap; word-wrap: break-word;">This patch is more about code maintainability rather than optimization. Using talloc_zero() or memset(ptr, 0x00, sizeof(*ptr)) makes it harder to find bugs, because neither ASan/UBSan nor Valgrind would be able to tell you that something was not properly initialized somewhere.</p><p style="white-space: pre-wrap; word-wrap: break-word;">For example, it took me a while to find the reason of printing warnings about deprecated VTY commands to stdin instead of stderr (see https://gerrit.osmocom.org/c/libosmocore/+/16138). The reason was that vty->fd was not initialized explicitly (bug), and 'thanks' to talloc_zero() it was set to stdin (fd=0) by default. If we were using explicit initialization, ASan would uncover that bug even before somebody noticed it.</p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">The only thing I like about talloc_zero() and zero-initialization in general is that it guards us from unexpected behaviour.<br> <br>> What if somebody inrtoduces new fields into the struct at some later point?  And if those are not explicitly initialized?</pre><p style="white-space: pre-wrap; word-wrap: break-word;">The new fields can be initialized explicitly unless the struct is too big...</p><p style="white-space: pre-wrap; word-wrap: break-word;">From the Python's Zen: "Explicit is better than implicit". I believe it applies here too.</p><p><a href="https://gerrit.osmocom.org/c/libosmocore/+/17218">View Change</a></p><ul style="list-style: none; padding: 0;"></ul><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmocore/+/17218">change 17218</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.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.osmocom.org/c/libosmocore/+/17218"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: libosmocore </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I40c0322d5f2febd98bae6fbe0ec2132eda6fb35b </div>
<div style="display:none"> Gerrit-Change-Number: 17218 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: fixeria <axilirator@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: fixeria <axilirator@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-CC: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-Comment-Date: Wed, 19 Feb 2020 11:19: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>