Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: tsnee@gibbs.oit.unc.edu (Tom Snee)
Subject: Pointer alignment/unaligned data access problem with [g]dbm
Date: 10 Jul 1993 22:59:53 GMT	[thread overview]
Message-ID: <21nhl9$8mp@samba.oit.unc.edu> (raw)



When I use gdbm or dbm on a DECstation running Ultrix (the only platform
I have tried), I have some strange problems.  The dbm and gdbm database
routines return a structure called datum, defined as

typedef struct	{
	char	*dptr;		/* points to data to be stored/fetched */
	int	dsize;		/* size of data */
} datum;

To store a structure in the database, I use something like

	struct mystructure	rec, *recptr;
	datum	key, content;

	key.dptr = keystr;
	key.dsize = strlen(keystr);
	content.dptr = &rec;
	content.dsize = sizeof(struct mystructure);
	store(key, content);

To get the structure back,

	content = fetch(key);
	recptr = (struct mystructure *) content.dptr;

On this last line, lint says "Possible pointer alignment problem."
Compiling and running the code always works, although sometimes I get the
runtime warning
"Fixed up unaligned data access for pid XXXX (procname) at pc 0x400a18."
dbx informs me that this location is a printf statement, where I try to
print out fields of the structure I got back from dbm.

I don't get these errors if "mystructure" contains only char arrays, but
I do if the structure has chars and ints.

What is going on?  Thanks.

						Tom Snee


                 reply	other threads:[~1993-07-10 22:59 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