From: Harald Koenig <koenig@tat.physik.uni-tuebingen.de>
Subject: alignment problem in procps-0.99a
Date: Fri, 26 Apr 1996 21:54:27 +0200 (MET DST) [thread overview]
Message-ID: <9604271556.AA11251@nova.tat.physik.uni-tuebingen.de> (raw)
Hi,
below is a fix for storing misaligned pointers which is needed for linux-alpha
Harald
-------------------------------------------------------------------------------
--- procps-0.99a/proc/readproc.c.ORIG Sun Feb 25 02:31:32 1996
+++ procps-0.99a/proc/readproc.c Fri Apr 26 21:46:46 1996
@@ -123,6 +123,7 @@
char buf[2048]; /* read buf bytes at a time */
char *p, *rbuf = 0, *endbuf, **q, **ret;
int fd, tot = 0, n, c, end_of_file = 0;
+ int align;
sprintf(buf, "%s/%s", directory, what);
if ( (fd = open(buf, O_RDONLY, 0) ) == -1 ) return NULL;
@@ -150,14 +151,15 @@
return NULL; /* read error */
}
endbuf = rbuf + tot; /* count space for pointers */
+ align = (sizeof(char*)-1) - ((tot + sizeof(char*)-1) & (sizeof(char*)-1));
for (c = 0, p = rbuf; p < endbuf; p++)
if (!*p)
c += sizeof(char*);
c += sizeof(char*); /* one extra for NULL term */
- rbuf = realloc(rbuf, tot + c); /* make room for ptrs AT END */
+ rbuf = realloc(rbuf, tot + c + align); /* make room for ptrs AT END */
endbuf = rbuf + tot; /* addr just past data buf */
- q = ret = (char**) endbuf; /* ==> free(*ret) to dealloc */
+ q = ret = (char**) (endbuf+align); /* ==> free(*ret) to dealloc */
*q++ = p = rbuf; /* point ptrs to the strings */
endbuf--; /* do not traverse final NUL */
while (++p < endbuf)
--
All SCSI disks will from now on ___ _____
be required to send an email notice 0--,| /OOOOOOO\
24 hours prior to complete hardware failure! <_/ / /OOOOOOOOOOO\
\ \/OOOOOOOOOOOOOOO\
\ OOOOOOOOOOOOOOOOO|//
Harald Koenig, \/\/\/\/\/\/\/\/\/
Inst.f.Theoret.Astrophysik // / \\ \
koenig@tat.physik.uni-tuebingen.de ^^^^^ ^^^^^
reply other threads:[~1996-04-26 19:54 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox