fixeria has posted comments on this change. (
https://gerrit.osmocom.org/c/libosmocore/+/31505 )
Change subject: gsm/{bsslap,bssmap_le}: zero-initialize structs using memset()
......................................................................
Patch Set 2:
(1 comment)
Patchset:
PS1:
oh. Actually in API functions it is fine for padding
bytes to be returned random.
Yes, it's fine. Because a regular user does not care about padding bytes in structs.
But the unit test does, because it uses `memcpy()` to compare the whole chunk of memory.
except if you are saying, a struct that has been
memset(0) has its padding bytes overwritten randomly by *foo = (struct foo){} ... in my
world so far that does not happen, but if zero padding does not stay zero, that would be a
reason to memset(0) in the API implementation too, and that would change how I understand
struct initialization.
This is exactly what I am saying and for me this was a new experience seeing that valgrind
reports (I was not able to reproduce this with ASAN) uninitialized memory access, despite
that part of memory has been explicitly initialized in the unit test with `memset()`. The
C11 standard is clear on this though: "... the bytes of the object representation
that correspond to any padding bytes take unspecified values".
I just find memset(0) looks ugly, and regression tests
are allowed to look ugly, API implementations not so much.
Agreeing with Harald here. I see nothing wrong using it.
We should actually be careful with `{}`, as it's a non-standard GCC's extension.
https://stackoverflow.com/questions/17589533/is-an-empty-initializer-list-v…
--
To view, visit
https://gerrit.osmocom.org/c/libosmocore/+/31505
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ib16964b16eb04315efc416164ed46c15b5dc7254
Gerrit-Change-Number: 31505
Gerrit-PatchSet: 2
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Comment-Date: Sat, 25 Feb 2023 08:59:56 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: neels <nhofmeyr(a)sysmocom.de>
Comment-In-Reply-To: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: comment