Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
* Pointer alignment/unaligned data access problem with [g]dbm
@ 1993-07-10 22:59 Tom Snee
  0 siblings, 0 replies; only message in thread
From: Tom Snee @ 1993-07-10 22:59 UTC (permalink / 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


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

only message in thread, other threads:[~1993-07-10 22:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1993-07-10 22:59 Pointer alignment/unaligned data access problem with [g]dbm Tom Snee

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