From 59ccff942cacea7bc3a0928189fc1acf602b5f6e Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Mon, 30 Jun 2008 07:00:58 +0300 Subject: [PATCH] libdpkg: Constify strings members for package db structs --- ChangeLog | 12 ++++++++++++ lib/dpkg-db.h | 22 ++++++++++++++-------- lib/parse.c | 6 +++--- src/processarc.c | 6 ++++-- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index d2e4b5ed..f549aefe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2008-06-30 Guillem Jover + + * lib/dpkg-db.h (struct arbitraryfield): Make all 'char *' members + 'const'. + (struct filedetails): Likewise. + (struct pkginfoperfile): Likewise. + (struct trigpend): Likewise. + + * lib/parse.c (parsedb): Remove now unneeded 'const char **' casts. + * src/processarc.c (process_archive): Change size variable before + assigning the pointer. + 2008-06-30 Guillem Jover * dselect/baselist.cc (baselist::wordwrapinfo): Surround expression diff --git a/lib/dpkg-db.h b/lib/dpkg-db.h index ba74c232..7d28970d 100644 --- a/lib/dpkg-db.h +++ b/lib/dpkg-db.h @@ -77,8 +77,8 @@ struct deppossi { struct arbitraryfield { struct arbitraryfield *next; - char *name; - char *value; + const char *name; + const char *value; }; struct conffile { @@ -90,10 +90,10 @@ struct conffile { struct filedetails { struct filedetails *next; - char *name; - char *msdosname; - char *size; - char *md5sum; + const char *name; + const char *msdosname; + const char *size; + const char *md5sum; }; struct pkginfoperfile { /* pif */ @@ -101,7 +101,13 @@ struct pkginfoperfile { /* pif */ struct dependency *depends; struct deppossi *depended; int essential; /* The `essential' flag, 1=yes, 0=no (absent) */ - char *description, *maintainer, *source, *architecture, *installedsize, *origin, *bugs; + const char *description; + const char *maintainer; + const char *source; + const char *architecture; + const char *installedsize; + const char *origin; + const char *bugs; struct versionrevision version; struct conffile *conffiles; struct arbitraryfield *arbs; @@ -114,7 +120,7 @@ struct trigpend { * trigger cycle checker (see trigproc.c). */ struct trigpend *next; - char *name; + const char *name; }; struct trigaw { diff --git a/lib/parse.c b/lib/parse.c index 99968c1e..cc6ed497 100644 --- a/lib/parse.c +++ b/lib/parse.c @@ -241,16 +241,16 @@ int parsedb(const char *filename, enum parsedbflags flags, parse_must_have_field(filename, lno, &newpig, newpig.name, "package name"); if ((flags & pdb_recordavailable) || newpig.status != stat_notinstalled) { parse_ensure_have_field(filename, lno, warnto, warncount, &newpig, - (const char **)&newpifp->description, "description"); + &newpifp->description, "description"); parse_ensure_have_field(filename, lno, warnto, warncount, &newpig, - (const char **)&newpifp->maintainer, "maintainer"); + &newpifp->maintainer, "maintainer"); if (newpig.status != stat_halfinstalled) parse_must_have_field(filename, lno, &newpig, newpifp->version.version, "version"); } if (flags & pdb_recordavailable) parse_ensure_have_field(filename, lno, warnto, warncount, &newpig, - (const char **)&newpifp->architecture, "architecture"); + &newpifp->architecture, "architecture"); /* Check the Config-Version information: * If there is a Config-Version it is definitely to be used, but diff --git a/src/processarc.c b/src/processarc.c index c93d12ee..cbcff6b7 100644 --- a/src/processarc.c +++ b/src/processarc.c @@ -68,6 +68,7 @@ void process_archive(const char *filename) { struct pkginfo *pkg, *otherpkg, *divpkg; char *cidir, *cidirrest, *p; char *pfilenamebuf, conffilenamebuf[MAXCONFFILENAME]; + char *psize; const char *pfilename, *newinfofilename, *failed; struct fileinlist *newconff, **newconffileslastp; struct fileinlist *cfile; @@ -198,8 +199,9 @@ void process_archive(const char *filename) { pkg->files->name = pkg->files->msdosname = pkg->files->md5sum = NULL; } /* Always nfmalloc. Otherwise, we may overwrite some other field(like md5sum). */ - pkg->files->size= nfmalloc(30); - sprintf(pkg->files->size,"%lu",(unsigned long)stab.st_size); + psize = nfmalloc(30); + sprintf(psize, "%lu", (unsigned long)stab.st_size); + pkg->files->size = psize; if (cipaction->arg == act_avail) { printf(_("Recorded info about %s from %s.\n"),pkg->name,pfilename); -- 2.39.5