From eb483c17ebb9a47c8b99b4319e682ab685213090 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Wed, 4 Jun 2008 06:30:36 +0300 Subject: [PATCH] Use new VARBUF_INIT macro instead of varbufinit to initialize variables --- ChangeLog | 17 +++++++++++++++++ lib/compression.c | 8 ++------ lib/dpkg-db.h | 5 ++++- lib/dump.c | 6 ++---- lib/mlib.c | 3 +-- lib/showpkg.c | 6 +----- src/archives.c | 9 ++------- src/configure.c | 6 ++---- src/depcon.c | 3 +-- src/main.c | 4 ++-- src/packages.c | 6 ++---- src/query.c | 4 +--- src/remove.c | 3 +-- src/select.c | 6 ++---- 14 files changed, 40 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index b683f064..b823e598 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2008-06-04 Guillem Jover + + * lib/dpkg-db.h (VARBUF_INIT): New macro. + * lib/compression.c (decompress_cat, compress_cat): Use VARBUF_INIT + instead of varbufinit to initialize the variables. + * lib/dump.c (writerecord, writedb): Likewise. + * lib/mlib.c (buffer_copy_setup_dual): Likewise. + * lib/showpkg.c (show1package): Likewise. + * src/archives.c (check_breaks, check_conflict): Likewise. + * src/configure.c (deferred_configure): Likewise. + * src/depcon.c (describedepcon): Likewise. + * src/main.c (commandfd): Likewise. + * src/packages.c (breaks_check_one, dependencies_ok): Likewise. + * src/query.c (searchfiles): Likewise. + * src/remove.c (deferred_remove): Likewise. + * src/select.c (setselections): Likewise. + 2008-06-04 Guillem Jover * src/archives.c (archivefiles): Use varbufreset instead of varbufinit diff --git a/lib/compression.c b/lib/compression.c index 07ab5dc3..df2d251a 100644 --- a/lib/compression.c +++ b/lib/compression.c @@ -36,9 +36,7 @@ fd_fd_filter(int fd_in, int fd_out, void decompress_cat(enum compress_type type, int fd_in, int fd_out, char *desc, ...) { va_list al; - struct varbuf v; - - varbufinit(&v); + struct varbuf v = VARBUF_INIT; va_start(al,desc); varbufvprintf(&v, desc, al); @@ -103,11 +101,9 @@ void decompress_cat(enum compress_type type, int fd_in, int fd_out, char *desc, void compress_cat(enum compress_type type, int fd_in, int fd_out, const char *compression, char *desc, ...) { va_list al; - struct varbuf v; + struct varbuf v = VARBUF_INIT; char combuf[6]; - varbufinit(&v); - va_start(al,desc); varbufvprintf(&v, desc, al); va_end(al); diff --git a/lib/dpkg-db.h b/lib/dpkg-db.h index 04ea77d6..fedaa3c6 100644 --- a/lib/dpkg-db.h +++ b/lib/dpkg-db.h @@ -366,6 +366,8 @@ const char *versiondescribe(const struct versionrevision*, struct varbuf; +#define VARBUF_INIT { 0, 0, NULL } + extern void varbufaddc(struct varbuf *v, int c); extern void varbufdupc(struct varbuf *v, int c, ssize_t s); int varbufprintf(struct varbuf *v, const char *fmt, ...) PRINTFFORMAT(2,3); @@ -378,7 +380,8 @@ void varbuffree(struct varbuf *v); extern void varbufaddbuf(struct varbuf *v, const void *s, const int l); /* varbufinit must be called exactly once before the use of each varbuf - * (including before any call to varbuffree). + * (including before any call to varbuffree), or the variable must be + * initialized with VARBUF_INIT. * * However, varbufs allocated `static' are properly initialised anyway and * do not need varbufinit; multiple consecutive calls to varbufinit before diff --git a/lib/dump.c b/lib/dump.c index a1fa0914..30bfadc7 100644 --- a/lib/dump.c +++ b/lib/dump.c @@ -337,9 +337,8 @@ void varbufrecord(struct varbuf *vb, void writerecord(FILE *file, const char *filename, const struct pkginfo *pigp, const struct pkginfoperfile *pifp) { - struct varbuf vb; + struct varbuf vb = VARBUF_INIT; - varbufinit(&vb); varbufrecord(&vb,pigp,pifp); varbufaddc(&vb,'\0'); if (fputs(vb.buf,file) < 0) @@ -357,7 +356,7 @@ void writedb(const char *filename, int available, int mustsync) { char *oldfn, *newfn; const char *which; FILE *file; - struct varbuf vb; + struct varbuf vb = VARBUF_INIT; int old_umask; which= available ? "available" : "status"; @@ -365,7 +364,6 @@ void writedb(const char *filename, int available, int mustsync) { strcpy(oldfn,filename); strcat(oldfn,OLDDBEXT); newfn= m_malloc(strlen(filename)+sizeof(NEWDBEXT)); strcpy(newfn,filename); strcat(newfn,NEWDBEXT); - varbufinit(&vb); old_umask = umask(022); file= fopen(newfn,"w"); diff --git a/lib/mlib.c b/lib/mlib.c index a6eda5c1..976dc3ef 100644 --- a/lib/mlib.c +++ b/lib/mlib.c @@ -265,10 +265,9 @@ off_t buffer_copy_setup_##name(type1 n1, int typeIn, void *procIn,\ {\ va_list al;\ buffer_arg a1, a2;\ - struct varbuf v;\ + struct varbuf v = VARBUF_INIT;\ off_t ret;\ a1.name1 = n1; a2.name2 = n2;\ - varbufinit(&v);\ va_start(al,desc);\ varbufvprintf(&v, desc, al);\ va_end(al);\ diff --git a/lib/showpkg.c b/lib/showpkg.c index 74e57c8c..85672e4c 100644 --- a/lib/showpkg.c +++ b/lib/showpkg.c @@ -199,16 +199,12 @@ struct lstitem* parseformat(const char* fmt) { void show1package(const struct lstitem* head, struct pkginfo *pkg) { - struct varbuf vb, fb, wb; + struct varbuf vb = VARBUF_INIT, fb = VARBUF_INIT, wb = VARBUF_INIT; /* Make sure we have package info available, even if it's all empty. */ if (!pkg->installed.valid) blankpackageperfile(&pkg->installed); - varbufinit(&vb); - varbufinit(&fb); - varbufinit(&wb); - while (head) { int ok; char fmt[16]; diff --git a/src/archives.c b/src/archives.c index a2022445..921d60e1 100644 --- a/src/archives.c +++ b/src/archives.c @@ -898,11 +898,9 @@ static int try_remove_can(struct deppossi *pdep, void check_breaks(struct dependency *dep, struct pkginfo *pkg, const char *pfilename) { struct pkginfo *fixbydeconf; - struct varbuf why; + struct varbuf why = VARBUF_INIT; int ok; - varbufinit(&why); - fixbydeconf = NULL; if (depisok(dep, &why, &fixbydeconf, 0)) { varbuffree(&why); @@ -956,11 +954,8 @@ void check_conflict(struct dependency *dep, struct pkginfo *pkg, const char *pfilename) { struct pkginfo *fixbyrm; struct deppossi *pdep, flagdeppossi; - struct varbuf conflictwhy, removalwhy; + struct varbuf conflictwhy = VARBUF_INIT, removalwhy = VARBUF_INIT; struct dependency *providecheck; - - varbufinit(&conflictwhy); - varbufinit(&removalwhy); fixbyrm = NULL; if (depisok(dep, &conflictwhy, &fixbyrm, 0)) { diff --git a/src/configure.c b/src/configure.c index cde2c688..4a8099a6 100644 --- a/src/configure.c +++ b/src/configure.c @@ -77,7 +77,8 @@ void deferred_configure(struct pkginfo *pkg) { * Try 4 (only if --force-depends). * Do anyway. */ - struct varbuf aemsgs, cdr, cdr2; + struct varbuf aemsgs = VARBUF_INIT; + struct varbuf cdr = VARBUF_INIT, cdr2 = VARBUF_INIT; char *cdr2rest; int ok, r, useredited, distedited; struct conffile *conff; @@ -99,7 +100,6 @@ void deferred_configure(struct pkginfo *pkg) { if (findbreakcycle(pkg)) sincenothing= 0; - varbufinit(&aemsgs); ok = dependencies_ok(pkg, NULL, &aemsgs); if (ok == 1) { varbuffree(&aemsgs); @@ -170,8 +170,6 @@ void deferred_configure(struct pkginfo *pkg) { * If `*.dpkg-new' no longer exists we assume that we've already * processed this one. */ - varbufinit(&cdr); - varbufinit(&cdr2); for (conff= pkg->installed.conffiles; conff; conff= conff->next) { r= conffderef(pkg, &cdr, conff->name); if (r == -1) { diff --git a/src/depcon.c b/src/depcon.c index 42d7b44c..fce092ca 100644 --- a/src/depcon.c +++ b/src/depcon.c @@ -149,7 +149,7 @@ int findbreakcycle(struct pkginfo *pkg) { void describedepcon(struct varbuf *addto, struct dependency *dep) { const char *fmt; - struct varbuf depstr; + struct varbuf depstr = VARBUF_INIT; switch (dep->type) { case dep_depends: @@ -177,7 +177,6 @@ void describedepcon(struct varbuf *addto, struct dependency *dep) { internerr("unknown deptype"); } - varbufinit(&depstr); varbufdependency(&depstr, dep); varbufaddc(&depstr, 0); diff --git a/src/main.c b/src/main.c index d92210a7..c2e294d1 100644 --- a/src/main.c +++ b/src/main.c @@ -517,7 +517,7 @@ void execbackend(const char *const *argv) { void commandfd(const char *const *argv) { jmp_buf ejbuf; - struct varbuf linevb; + struct varbuf linevb = VARBUF_INIT; const char * pipein; const char **newargs; char *ptr, *endptr; @@ -538,7 +538,7 @@ void commandfd(const char *const *argv) { if (setjmp(ejbuf)) { /* expect warning about possible clobbering of argv */ error_unwind(ehflag_bombout); exit(2); } - varbufinit(&linevb); + for (;;lno= 0) { const char **oldargs= NULL; int argc= 1, mode= 0; diff --git a/src/packages.c b/src/packages.c index 8d22ae40..24116dcb 100644 --- a/src/packages.c +++ b/src/packages.c @@ -453,7 +453,7 @@ static void breaks_check_one(struct varbuf *aemsgs, int *ok, struct pkginfo *broken, struct pkginfo *breaker, struct pkginfo *virtbroken) { - struct varbuf depmsg; + struct varbuf depmsg = VARBUF_INIT; debug(dbg_depcondetail, " checking breaker %s virtbroken %s", breaker->name, virtbroken ? virtbroken->name : ""); @@ -465,7 +465,6 @@ static void breaks_check_one(struct varbuf *aemsgs, int *ok, if (ignore_depends(breaker)) return; if (virtbroken && ignore_depends(virtbroken)) return; - varbufinit(&depmsg); varbufdependency(&depmsg, breaks->up); varbufaddc(&depmsg, 0); varbufprintf(aemsgs, _(" %s (%s) breaks %s and is %s.\n"), @@ -524,12 +523,11 @@ int breakses_ok(struct pkginfo *pkg, struct varbuf *aemsgs) { int dependencies_ok(struct pkginfo *pkg, struct pkginfo *removing, struct varbuf *aemsgs) { int ok, matched, found, thisf, interestingwarnings, anycannotfixbytrig; - struct varbuf oemsgs; + struct varbuf oemsgs = VARBUF_INIT; struct dependency *dep; struct deppossi *possi, *provider; struct pkginfo *possfixbytrig, *canfixbytrig; - varbufinit(&oemsgs); interestingwarnings= 0; ok= 2; /* 2=ok, 1=defer, 0=halt */ debug(dbg_depcon,"checking dependencies of %s (- %s)", diff --git a/src/query.c b/src/query.c index 094f48e4..9ab3e098 100644 --- a/src/query.c +++ b/src/query.c @@ -246,13 +246,11 @@ void searchfiles(const char *const *argv) { const char *thisarg; int found; struct varbuf path; - static struct varbuf vb; + static struct varbuf vb = VARBUF_INIT; if (!*argv) badusage(_("--search needs at least one file name pattern argument")); - varbufinit(&path); - modstatdb_init(admindir,msdbrw_readonly|msdbrw_noavail); ensure_allinstfiles_available_quiet(); ensure_diversions(); diff --git a/src/remove.c b/src/remove.c index 1e92d623..fc0f9c5e 100644 --- a/src/remove.c +++ b/src/remove.c @@ -84,7 +84,7 @@ static void checkforremoval(struct pkginfo *pkgtoremove, } void deferred_remove(struct pkginfo *pkg) { - struct varbuf raemsgs; + struct varbuf raemsgs = VARBUF_INIT; int rok; struct dependency *dep; @@ -117,7 +117,6 @@ void deferred_remove(struct pkginfo *pkg) { if (!f_noact) modstatdb_note(pkg); debug(dbg_general,"checking dependencies for remove `%s'",pkg->name); - varbufinit(&raemsgs); rok= 2; checkforremoval(pkg,pkg,&rok,&raemsgs); for (dep= pkg->installed.depends; dep; dep= dep->next) { diff --git a/src/select.c b/src/select.c index 4b535894..8bef660d 100644 --- a/src/select.c +++ b/src/select.c @@ -89,16 +89,14 @@ void setselections(const char *const *argv) { struct pkginfo *pkg; const char *e; int c, lno; - struct varbuf namevb; - struct varbuf selvb; + struct varbuf namevb = VARBUF_INIT; + struct varbuf selvb = VARBUF_INIT; if (*argv) badusage(_("--%s takes no arguments"), cipaction->olong); modstatdb_init(admindir,msdbrw_write); - varbufinit(&namevb); - varbufinit(&selvb); lno= 1; for (;;) { varbufreset(&namevb); -- 2.39.5