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

Re: Why does this program segfault?



<quote from the msg-header>
Subject: Why does this program segfault?
In-Reply-To: <[🔎] 20020114235823.L27861@cibalia.gkvk.hr>
</quote>
What does that have to do with Josip Rodin's comment about the sponsoring of 
non-free packages ? (Hint: fix your mail-client)


On Tuesday 15 January 2002 01:11, Jaldhar H. Vyas wrote:
> Is it because pkgDepCache has a virtual destructor?  If so am I supposed
> to subclass it or am I just using it the wrong way?  (Sorry, the the
> intricacies of C++ are a bit hazy for me and libapt-pkg is practically
> undocumented.)
>
Hmmm, what about a backtrace ?

> /*
>  * Compile it like this:
>  * $ c++ -O2 -Wall -s -o showpackages showpackages.cc -lapt-pkg
>  */
>
> #include <iostream>
> #include <apt-pkg/cachefile.h>
> #include <apt-pkg/init.h>
> #include <apt-pkg/pkgcache.h>
> #include <apt-pkg/progress.h>
>
> int main ()
> {
>   if (!pkgInitConfig(*_config) || !pkgInitSystem(*_config, _system))
*ouch*. This is forbidden by the standard, having identifiers beginning with 
an underscore, they are reserved for use by compiler-internals. Especially 
really generic identifiers like _config or _system are a plain invitation for 
collisions.

If this is required by the apt-pkg libs, this is worth a but-report (but only 
with a patch, so I will investigate a bit...).

>   pkgDepCache cache = *cachefile;
I am not sure if this is intended to be used that way, that is if the 
copy-operation is really fully implemented (usually, you would rather not 
copy the Object but ust pass references or pointers). Try to make this line 
  pkgDepCache& cache = *cachefile;

>   for (pkgCache::PkgIterator it = cache.PkgBegin(); !it.end(); it++)
this loop is a bit different from typical C++, there you would probably have 
something like 
for (pkgCache::PkgIterator it = cache.PkgBegin(); it!=cache.PkgEnd(); ++it)
but that is not necessarily wrong.

A last question that comes up is what parts of the program can be removed so 
it doesn't segfault?

Uli



Reply to: