Corrupted strings coming from libapt-pkg

  apt, c++, lib, ubuntu

I’m attempting to make a GUI package manager for Ubuntu similar to Synaptic which uses libapt but have run into a few strange bugs to do with getting information from the pkgCache. Specifically when using a pkgIterator and trying to access the FullName() and Name() properties but others like Section() are fine (you can look at documentation here).

Looking at the way Synaptic does it, it is pretty simple and I tried replicating it 1:1 with no luck.

const char *name() {
    const char *n = package->Name();
    if (n == NULL)
        return "";
    return n;

Which will usually return some garbage string that looks like a null termination was missed. The interesting thing is that all of the strings for packages in the same group from repositories will have the same garbage text while locally installed packages will have a NULL pointer and therefore will return an empty string.

Any ideas? I believe that I’m opening the pkgCache correctly and the iterator is not NULL. Theres also not many places to look online when debugging libapt so any references would be helpful as well!.

Source: Windows Questions C++