Prechádzať zdrojové kódy

libdpkg: Constify strings members for package db structs

Guillem Jover 18 rokov pred
rodič
commit
59ccff942c
4 zmenil súbory, kde vykonal 33 pridanie a 13 odobranie
  1. 12 0
      ChangeLog
  2. 14 8
      lib/dpkg-db.h
  3. 3 3
      lib/parse.c
  4. 4 2
      src/processarc.c

+ 12 - 0
ChangeLog

@@ -1,3 +1,15 @@
+2008-06-30  Guillem Jover  <guillem@debian.org>
+
+	* 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  <guillem@debian.org>
 
 	* dselect/baselist.cc (baselist::wordwrapinfo): Surround expression

+ 14 - 8
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 {

+ 3 - 3
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

+ 4 - 2
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);