Change in libosmocore[master]: bitvec: avoid redundant zero-initialization in bitvec_alloc()

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

fixeria gerrit-no-reply at lists.osmocom.org
Wed Feb 19 11:19:52 UTC 2020


fixeria has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/17218 )

Change subject: bitvec: avoid redundant zero-initialization in bitvec_alloc()
......................................................................


Patch Set 1:

> I'm not a big fan of such over-optimization patches.

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.

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.

The only thing I like about talloc_zero() and zero-initialization in general is that it guards us from unexpected behaviour.
 
> What if somebody inrtoduces new fields into the struct at some later point?  And if those are not explicitly initialized?

The new fields can be initialized explicitly unless the struct is too big...

>From the Python's Zen: "Explicit is better than implicit". I believe it applies here too.


-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/17218
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I40c0322d5f2febd98bae6fbe0ec2132eda6fb35b
Gerrit-Change-Number: 17218
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <axilirator at gmail.com>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <axilirator at gmail.com>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-CC: laforge <laforge at osmocom.org>
Gerrit-Comment-Date: Wed, 19 Feb 2020 11:19:52 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200219/f9671e38/attachment.htm>


More information about the gerrit-log mailing list