Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* alignment problem in procps-0.99a
@ 1996-04-26 19:54 Harald Koenig
  0 siblings, 0 replies; only message in thread
From: Harald Koenig @ 1996-04-26 19:54 UTC (permalink / 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                     ^^^^^       ^^^^^

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1996-04-26 19:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-04-26 19:54 alignment problem in procps-0.99a Harald Koenig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox