[gPXE] ptr_to_struct->member != ptr_to_struct + offsetof(struct, member)
sobtwmxt
sobtwmxt at sdf.lonestar.org
Wed Nov 25 20:20:04 EST 2009
1. Why the following asserion fail? How to correct it?
struct person {
struct refcnt refcnt;
const char *givenName;
const char *fatherName;
};
fatherName = zalloc( 10 );
static void person_free_fatherName ( struct refcnt *refcnt ) {
struct person *person =
container_of ( refcnt, struct person, refcnt );
assert ( (void *) person->fatherName ==
(void *) uri +
offsetof(struct person, fatherName) );
free ( uri + offsetof(struct uri, decoded_user) );
};
2. I think I have the following 2 options in order to add a
decoded_[user:password] fields to struct uri:
1. Keep what is already there, and add aditional 2 fields,
namely decoded_user and decoded_password.
2. Replace the contents of the existing user and password
fields with the decoded information.
Although I traced only net/tcp/http.c and usr/imgmgmt.c that are
currently using it, initialy the replacment option seem to me more
likely to break things. Therefore, as of this writing, I coded
2 additional fields.
In order to add those decoded_[user:password], I think I must use
dynamic memory allocation. I can:
1. Create a
strcut decoded_info {
struct refcnt refcnt;
const char *user;
const char *password;
};
or
2. Add 2 plain pointers,
const char *decoded_user;
const char *decoded_password;
Is strcut decoded_info better then 2 plain char *ptr, or vice
versa?
--
sobtwmxt at sdf.lonestar.org
SDF Public Access UNIX System - http://sdf.lonestar.org
More information about the gPXE
mailing list