[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Fix for Zope segfault on amd64



*** Regarding Re: Fix for Zope segfault on amd64; Vincent Hanquez
    <tab@snarc.org> adds:

Vincent> Please be specific then. point one architecture that zope
Vincent> support which did not fulfill this requirement.

There are versions of UNIX where gid_t is an unsigned short.  Whether
those are among the ones supported by Zope, I do not know, but that's
not the point.  Even if gid_t is always 32 bit you can still get in
trouble because int may be bigger on some platform, e.g., 64 bit.  I
think it is foolish to assume int is always 32 bit when writing
portable code.  Your proposed fix makes the assumption that
sizeof(gid_t) == sizeof(int).  If that isn't true, the code with your
fix will segfault or produce incorrect result on big endian
architectures.

Vincent> you cannot assume either that long should be big enough to
Vincent> support a gid_t (even if this likely to be the case for
Vincent> multiple decade and maybe forever...)  Then what about using
Vincent> long long to be sure ? or long long long ? see my point ?

Right, that is a concern.  However, my code will not segfault even if
gid_t is a bigger type than long because I declared the gid variable
long.  It is just not safe to pass a pointer to gid_t to
PyArg_ParseTuple().  If you use the i format specifier you should pass
a pointer to int.  If you use l, pass a pointer to long.  Then do the
conversion to the actual type you wanted after PyArg_ParseTuple() has
returned.

Per

-- 
Per Bojsen                                              <per.bojsen@comcast.net>
7 Francis Road
Billerica, MA 01821-3618
USA



Reply to: