From 17aa6b25cb0b720279f5d8221de17b01398d0143 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sun, 22 Jun 2014 16:53:55 +0200 Subject: osmo-auc-gen: Fix compiler warnings about aliasing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I ran "./utils/osmo-auc-gen -2 -a COMP128v1" and verified that the RAND doen't look empty Fixes: osmo-auc-gen.c: In function ‘main’: osmo-auc-gen.c:219:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] *(uint32_t *)&_rand[0] = rand(); ^ osmo-auc-gen.c:220:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] *(uint32_t *)(&_rand[4]) = rand(); ^ osmo-auc-gen.c:221:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] *(uint32_t *)(&_rand[8]) = rand(); ^ osmo-auc-gen.c:222:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] *(uint32_t *)(&_rand[12]) = rand(); --- utils/osmo-auc-gen.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'utils') diff --git a/utils/osmo-auc-gen.c b/utils/osmo-auc-gen.c index ee349ae6..fda045aa 100644 --- a/utils/osmo-auc-gen.c +++ b/utils/osmo-auc-gen.c @@ -214,12 +214,15 @@ int main(int argc, char **argv) } if (!rand_is_set) { + int i; printf("WARNING: We're using really weak random numbers!\n\n"); srand(time(NULL)); - *(uint32_t *)&_rand[0] = rand(); - *(uint32_t *)(&_rand[4]) = rand(); - *(uint32_t *)(&_rand[8]) = rand(); - *(uint32_t *)(&_rand[12]) = rand(); + + for (i = 0; i < 4; ++i) { + uint32_t r; + r = rand(); + memcpy(&_rand[i*4], &r, 4); + } } if (test_aud.type == OSMO_AUTH_TYPE_NONE || -- cgit v1.2.3