Skip to content

Commit 1947b3f

Browse files
committed
Fix UBSAN warnings in oct-group.cc (bug #67193)
* oct-group.cc: Define temporary variable of type "struct ::group" which compiler will correctly align in memory. Use std::memcpy to copy potentially non-aligned data from libary function call to new aligned local variable.
1 parent 62b4396 commit 1947b3f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

liboctave/system/oct-group.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,12 @@ group::group (void *p, std::string& msg)
196196

197197
if (p)
198198
{
199-
struct ::group *gr = static_cast<struct ::group *> (p);
199+
// struct ::group *gr = static_cast<struct ::group *> (p);
200+
// Ths code assumes memory alignment that is not the case on MacOS.
201+
// Copy struct group to aligned local storage.
202+
struct ::group tmpgr;
203+
std::memcpy (&tmpgr, p, sizeof (tmpgr));
204+
struct ::group *gr = &tmpgr;
200205

201206
m_name = gr->gr_name;
202207

0 commit comments

Comments
 (0)