From: Derrick Brashear Date: Fri, 24 May 2002 23:05:47 +0000 (+0000) Subject: viced-malloc-dont-make-assumptions-about-the-compiler-20020524 X-Git-Tag: openafs-devel_1_3_3~118 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=bbab90943637385742923c8bebebdd750a283e5c;p=packages%2Fo%2Fopenafs.git viced-malloc-dont-make-assumptions-about-the-compiler-20020524 based on report from lha@stacken.kth.se "identP = (struct Identity *)malloc(1); This can't be right, there should not be an assumption how the c-compiler will lay out code. I find it acceptable to do something like this /* sizeof valid + offset of valid. */ i.. = malloc(sizeof(identP->valid) + (int)&(((struct Identity *)0)->valid)); But then, why not just allocate a whole identP and be happy. A afsUUID is not that bloted (16 bytes) so I can't see why way this is chosen. 20 bytes will probably be allocated on 32 bit platforms for the whole struct Identity. " --- diff --git a/src/viced/host.c b/src/viced/host.c index 98de75dfd..2748f2bbd 100644 --- a/src/viced/host.c +++ b/src/viced/host.c @@ -987,7 +987,7 @@ retry: code = RXAFSCB_WhoAreYou(host->callback_rxcon, &interf); H_LOCK if ( code == RXGEN_OPCODE ) { - identP = (struct Identity *)malloc(1); + identP = (struct Identity *)malloc(sizeof(struct Identity)); identP->valid = 0; rx_SetSpecific(tcon, rxcon_ident_key, identP); /* The host on this connection was unable to respond to @@ -1072,7 +1072,7 @@ retry: code = RXAFSCB_WhoAreYou(host->callback_rxcon, &interf); H_LOCK if ( code == RXGEN_OPCODE ) { - identP = (struct Identity *)malloc(1); + identP = (struct Identity *)malloc(sizeof(struct Identity)); identP->valid = 0; rx_SetSpecific(tcon, rxcon_ident_key, identP); ViceLog(25,