Subject: Re: pkgdb_remove_pkg() needs cc + 1
To: Jeremy C. Reed <reed@reedmedia.net>
From: David Laight <david@l8s.co.uk>
List: tech-pkg
Date: 04/11/2003 10:26:27
On Fri, Apr 11, 2003 at 01:45:18AM -0700, Jeremy C. Reed wrote:
> pkgdb_remove_pkg() function in usr.sbin/pkg_install/lib/pkgdb.c has:
> cc = strlen(pkg);
>
> I think it should be:
> cc = strlen(pkg) + 1;
>
> I think it never matched in pkg_delete's OnlyDeleteFromPkgDB.
>
> Can someone check this?
I tend to agree - but has no idea what the code is trying to do!
cc is only used to do:
if (cc == data.size && strncmp(data.data, pkg, cc) == 0) {
But elsewhere it has:
vald.data = (void *) key;
vald.size = strlen(key) + 1;
If (and it does look that way) all the key/data are saved as null terminated
strings, then the code is attempting to optimise the search by checking
the length before the str(n)cmp.
Provided there is a null on data.data, then it will be faster to use
strcmp instead of strncmp. Also checking data.data[0] == pkg[0]
before calling strcmp will help.
David
--
David Laight: david@l8s.co.uk