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

Re: Why does this program segfault?



On Tue, 15 Jan 2002, Glenn Maynard wrote:

> By the way, Jaldhar, don't reply to a message to post a new thread on
> mailing lists.  It gets your thread tagged as a subthread.
>

Sorry, that was just me being lazy.

> Unrelated nitpick: use ++it for iterators; it doesn't matter for most,
> but it can be a lot faster for classes with non-trivial iteraters, so
> it's a good habit.
>

Good point, the code is fixed accordingly.

> free(NULL) is fine;

Well, strictly speaking it is calling delete which in the GNU C++
implementation ends up calling free.  I seem to remember something about a
C++ idiom being defining a class which is meant to be subclassed with a
virtual destructor so if the base is used by itself, this kind of
thing happens on purpose.  Or something, I use C++ too infrequently to
fully master such a hairy language.

>
> I don't know this library, but if it's being used right, it's a library
> bug.  (If it's not, then it might still be a library bug; you're doing
> an assignment that it allows, so it shouldn't explode.)
>
> Something odd happens with "pkgDepCache cache = *cachefile;"; it works
> with "pkgDepCache cache((pkgCache *)cachefile);".  Remove the cast and
> you get an ambiguous overload error.  Probably something amiss with the
> added casts in pkgCacheFile.
>

What I've been able to gather from the comments in the source is that
libapt-pkg does fancy things with mmap(2)  so it's not all straightforward
pointers and structs.

-- 
Jaldhar H. Vyas <jaldhar@debian.org>
It's a girl! See the pictures - http://www.braincells.com/shailaja/



Reply to: