From ea93ed48c17445d01b67f3fa8a20a5a644a89e5b Mon Sep 17 00:00:00 2001 From: Adam Heath Date: Mon, 23 Apr 2001 08:59:02 +0000 Subject: [PATCH] Fixed up several warning types: const, casting, incorrect sizes, signed/unsigned comparisons. --- ChangeLog | 10 ++++++++++ dpkg-deb/build.c | 9 +++++---- dpkg-deb/extract.c | 2 +- dpkg-deb/main.c | 2 +- dselect/pkglist.cc | 12 ++++++------ dselect/pkglist.h | 2 +- dselect/pkgtop.cc | 2 +- include/dpkg-db.h | 25 +++++++++---------------- include/dpkg.h.in | 10 +++++----- lib/dump.c | 8 ++++---- lib/ehandle.c | 2 +- lib/fields.c | 23 ++++++++++++++--------- lib/mlib.c | 2 +- lib/parse.c | 8 ++++---- lib/parsedump.h | 4 ++-- lib/parsehelp.c | 2 +- lib/varbuf.c | 4 ++-- lib/vercmp.c | 16 ++++++++++------ main/archives.c | 30 ++++++++++++++++-------------- main/configure.c | 2 +- main/enquiry.c | 6 +++--- main/filesdb.c | 7 ++++--- main/filesdb.h | 2 +- main/help.c | 17 ++++++++--------- main/main.c | 14 ++++++++++---- main/main.h | 2 +- main/packages.c | 4 ++-- main/processarc.c | 4 ++-- main/remove.c | 4 ++-- split/dpkg-split.h | 8 ++++---- split/info.c | 5 +++-- split/join.c | 6 +++--- split/main.c | 2 +- split/queue.c | 6 ++++-- utils/md5sum.c | 4 ++-- utils/start-stop-daemon.c | 8 ++++---- 36 files changed, 149 insertions(+), 125 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6a177c3e..5b9cbaea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Mon Apr 23 03:21:10 CDT 2001 Adam Heath + + * dpkg-deb/{build,extract,main}.c, split/{info,join,main,queue}.c, + split/dpkg-split.h, lib/{dump,ehandle,fields,mlib,parse{,help},varbuf, + vercmp}.c, lib/parsedump.h, main/{archives,configure,enquiry,filesdb, + help,main,packages,processarc,remove}.c, main/{filesdb,main}.h, + utils/{md5sum, start-stop-daemon}.c, dselect/pkg{list.cc,list.hh, + top.cc}, include/dpkg{-db.h,.h.in}: Fixed up several warning types. + const, casting, incorrect sizes, signed/unsigned comparisons. + Mon Apr 23 02:17:26 CDT 2001 Adam Heath * dpkg-deb/info.c, main/processarc.c: Add comments telling why we diff --git a/dpkg-deb/build.c b/dpkg-deb/build.c index beae6fa8..41ab539f 100644 --- a/dpkg-deb/build.c +++ b/dpkg-deb/build.c @@ -73,8 +73,8 @@ static void checkversion(const char *vstring, const char *valuename, int *errs) */ static struct _finfo* getfi(const char* root, int fd) { static char* fn = NULL; - static int fnlen = 0; - int i = 0; + static size_t fnlen = 0; + size_t i= 0; struct _finfo *fi; size_t rl = strlen(root); @@ -206,7 +206,8 @@ void do_build(const char *const *argv) { char *m; const char *debar, *directory, *const *mscriptp, *versionstring, *arch; - char *controlfile, *tfbuf, *envbuf; + char *controlfile, *tfbuf; + const char *envbuf; struct pkginfo *checkedinfo; struct arbitraryfield *field; FILE *ar, *gz, *cf; @@ -223,7 +224,7 @@ void do_build(const char *const *argv) { directory= *argv++; if (!directory) badusage(_("--build needs a directory argument")); /* template for our tempfiles */ if ((envbuf= getenv("TMPDIR")) == NULL) - envbuf= (char *)P_tmpdir; + envbuf= P_tmpdir; tfbuf = (char *)malloc(strlen(envbuf)+13); strcpy(tfbuf,envbuf); strcat(tfbuf,"/dpkg.XXXXXX"); diff --git a/dpkg-deb/extract.c b/dpkg-deb/extract.c index 46475e27..76091533 100644 --- a/dpkg-deb/extract.c +++ b/dpkg-deb/extract.c @@ -85,7 +85,7 @@ void extracthalf(const char *debar, const char *directory, char versionbuf[40]; float versionnum; char ctrllenbuf[40], *infobuf; - long ctrllennum, memberlen= 0; + size_t ctrllennum, memberlen= 0; int dummy, l= 0; pid_t c1=0,c2,c3; unsigned char *ctrlarea= 0; diff --git a/dpkg-deb/main.c b/dpkg-deb/main.c index bb801fd4..c1613861 100644 --- a/dpkg-deb/main.c +++ b/dpkg-deb/main.c @@ -136,7 +136,7 @@ static void setaction(const struct cmdinfo *cip, const char *value) { if (cipaction) badusage(_("conflicting actions --%s and --%s"),cip->olong,cipaction->olong); cipaction= cip; - assert(cip-cmdinfos < sizeof(dofunctions)*sizeof(dofunction*)); + assert((int)(cip-cmdinfos) < (int)(sizeof(dofunctions)*sizeof(dofunction*))); action= dofunctions[cip-cmdinfos]; } diff --git a/dselect/pkglist.cc b/dselect/pkglist.cc index 98833fed..8ef3d4b1 100644 --- a/dselect/pkglist.cc +++ b/dselect/pkglist.cc @@ -32,8 +32,8 @@ extern "C" { #include "dselect.h" #include "bindings.h" -int packagelist::compareentries(struct perpackagestate *a, - struct perpackagestate *b) { +int packagelist::compareentries(const struct perpackagestate *a, + const struct perpackagestate *b) { switch (statsortorder) { case sso_avail: if (a->ssavail != b->ssavail) return a->ssavail - b->ssavail; @@ -123,8 +123,8 @@ void packagelist::addheading(enum ssavailval ssavail, struct pkginfo *newhead= new pkginfo; newhead->name= 0; newhead->priority= priority; - newhead->otherpriority= (char*)otherpriority; - newhead->section= (char*)section; + newhead->otherpriority= otherpriority; + newhead->section= section; struct perpackagestate *newstate= new perpackagestate; newstate->pkg= newhead; @@ -140,8 +140,8 @@ void packagelist::addheading(enum ssavailval ssavail, static packagelist *sortpackagelist; int qsort_compareentries(const void *a, const void *b) { - return sortpackagelist->compareentries(*(perpackagestate**)a, - *(perpackagestate**)b); + return sortpackagelist->compareentries((const struct perpackagestate*)&a, + (const struct perpackagestate*)&b); } void packagelist::sortinplace() { diff --git a/dselect/pkglist.h b/dselect/pkglist.h index 4bfc8435..232227af 100644 --- a/dselect/pkglist.h +++ b/dselect/pkglist.h @@ -141,7 +141,7 @@ class packagelist : public baselist { // Miscellaneous internal routines void redraw1package(int index, int selected); - int compareentries(struct perpackagestate *a, struct perpackagestate *b); + int compareentries(const struct perpackagestate *a, const struct perpackagestate *b); friend int qsort_compareentries(const void *a, const void *b); pkginfo::pkgwant reallywant(pkginfo::pkgwant, struct perpackagestate*); int describemany(char buf[], const char *prioritystring, const char *section, diff --git a/dselect/pkgtop.cc b/dselect/pkgtop.cc index 4c6d763a..1a9bb617 100644 --- a/dselect/pkgtop.cc +++ b/dselect/pkgtop.cc @@ -183,7 +183,7 @@ void packagelist::redraw1itemsel(int index, int selected) { wmove(listpad,index,priority_column-1); waddch(listpad,' '); if (pkg->priority == pkginfo::pri_other) { int i; - char *p; + const char *p; for (i=priority_width, p=pkg->otherpriority; i > 0 && *p; i--, p++) diff --git a/include/dpkg-db.h b/include/dpkg-db.h index 5a84e3c9..ef760e30 100644 --- a/include/dpkg-db.h +++ b/include/dpkg-db.h @@ -81,8 +81,8 @@ struct arbitraryfield { struct conffile { struct conffile *next; - char *name; - char *hash; + const char *name; + const char *hash; }; struct filedetails { @@ -108,7 +108,7 @@ struct perpackagestate; /* dselect and dpkg have different versions of this */ struct pkginfo { /* pig */ struct pkginfo *next; - char *name; + const char *name; enum pkgwant { want_unknown, want_install, want_hold, want_deinstall, want_purge, want_sentinel /* Not allowed except as special sentinel value @@ -131,8 +131,8 @@ struct pkginfo { /* pig */ pri_optional, pri_extra, pri_contrib, pri_other, pri_unknown, pri_unset=-1 } priority; - char *otherpriority; - char *section; + const char *otherpriority; + const char *section; struct versionrevision configversion; struct filedetails *files; struct pkginfoperfile installed; @@ -257,7 +257,7 @@ extern void varbufaddbuf(struct varbuf *v, const void *s, const int l); * Callers using C++ need not worry about any of this. */ struct varbuf { - int used, size; + size_t used, size; char *buf; #ifdef __cplusplus @@ -265,21 +265,14 @@ struct varbuf { void free() { varbuffree(this); } varbuf() { varbufinit(this); } ~varbuf() { varbuffree(this); } - inline void operator()(int c); // definition below + void operator()(int c) { varbufaddc(this,c); } void operator()(const char *s) { varbufaddstr(this,s); } - inline void terminate(void/*to shut 2.6.3 up*/); // definition below + void terminate(void/*to shut 2.6.3 up*/) { varbufaddc(this,0); used--; } void reset() { used=0; } const char *string() { terminate(); return buf; } #endif }; -inline extern void varbufaddc(struct varbuf *v, int c); - -#ifdef __cplusplus -inline void varbuf::operator()(int c) { varbufaddc(this,c); } -inline void varbuf::terminate(void/*to shut 2.6.3 up*/) { varbufaddc(this,0); used--; } -#endif - /*** from dump.c ***/ void writerecord(FILE*, const char*, @@ -303,7 +296,7 @@ int epochsdiffer(const struct versionrevision *a, const struct versionrevision *b); /*** from nfmalloc.c ***/ -extern inline void *nfmalloc(size_t); +extern void *nfmalloc(size_t); char *nfstrsave(const char*); char *nfstrnsave(const char*, int); void nffreeall(void); diff --git a/include/dpkg.h.in b/include/dpkg.h.in index 14e5eab2..cc86616e 100644 --- a/include/dpkg.h.in +++ b/include/dpkg.h.in @@ -171,7 +171,7 @@ void print_error_fatal(const char *emsg, const char *contextstring); void error_unwind(int flagset); void push_cleanup(void (*f1)(int argc, void **argv), int flagmask1, void (*f2)(int argc, void **argv), int flagmask2, - int nargs, ...); + unsigned int nargs, ...); void push_checkpoint(int mask, int value); void pop_cleanup(int flagset); enum { ehflag_normaltidy=01, ehflag_bombout=02, ehflag_recursiveerror=04 }; @@ -263,16 +263,16 @@ struct buffer_data { buffer_copy_setup_PtrInt(file, BUFFER_READ_STREAM, NULL, \ fd, BUFFER_WRITE_FD, NULL, \ limit, desc) -inline ssize_t buffer_copy_setup_PtrInt(void *p, int typeIn, void *procIn, +ssize_t buffer_copy_setup_PtrInt(void *p, int typeIn, void *procIn, int i, int typeOut, void *procOut, ssize_t limit, const char *desc, ...); -inline ssize_t buffer_copy_setup_PtrPtr(void *p1, int typeIn, void *procIn, +ssize_t buffer_copy_setup_PtrPtr(void *p1, int typeIn, void *procIn, void *p2, int typeOut, void *procOut, ssize_t limit, const char *desc, ...); -inline ssize_t buffer_copy_setup_IntPtr(int i, int typeIn, void *procIn, +ssize_t buffer_copy_setup_IntPtr(int i, int typeIn, void *procIn, void *p, int typeOut, void *procOut, ssize_t limit, const char *desc, ...); -inline ssize_t buffer_copy_setup_IntInt(int i1, int typeIn, void *procIn, +ssize_t buffer_copy_setup_IntInt(int i1, int typeIn, void *procIn, int i2, int typeOut, void *procOut, ssize_t limit, const char *desc, ...); ssize_t buffer_copy_setup(buffer_arg argIn, int typeIn, void *procIn, diff --git a/lib/dump.c b/lib/dump.c index acd81a3f..6cbfe8b6 100644 --- a/lib/dump.c +++ b/lib/dump.c @@ -82,7 +82,7 @@ void w_section(struct varbuf *vb, void w_charfield(struct varbuf *vb, const struct pkginfo *pigp, const struct pkginfoperfile *pifp, const struct fieldinfo *fip) { - const char *value= pifp->valid ? PKGPFIELD(pifp,fip->integer,char*) : 0; + const char *value= pifp->valid ? PKGPFIELD(pifp,fip->integer,const char*) : 0; if (!value || !*value) return; varbufaddstr(vb,fip->name); varbufaddstr(vb, ": "); varbufaddstr(vb,value); varbufaddc(vb,'\n'); @@ -95,11 +95,11 @@ void w_filecharf(struct varbuf *vb, if (pifp != &pigp->available) return; fdp= pigp->files; - if (!fdp || !FILEFFIELD(fdp,fip->integer,char*)) return; + if (!fdp || !FILEFFIELD(fdp,fip->integer,const char*)) return; varbufaddstr(vb,fip->name); varbufaddc(vb,':'); while (fdp) { varbufaddc(vb,' '); - varbufaddstr(vb,FILEFFIELD(fdp,fip->integer,char*)); + varbufaddstr(vb,FILEFFIELD(fdp,fip->integer,const char*)); fdp= fdp->next; } varbufaddc(vb,'\n'); @@ -108,7 +108,7 @@ void w_filecharf(struct varbuf *vb, void w_booleandefno(struct varbuf *vb, const struct pkginfo *pigp, const struct pkginfoperfile *pifp, const struct fieldinfo *fip) { - int value= pifp->valid ? PKGPFIELD(pifp,fip->integer,int) : 0; + int value= pifp->valid ? PKGPFIELD(pifp,fip->integer,int) : -1; if (!value) return; assert(value==1); varbufaddstr(vb,"Essential: yes\n"); diff --git a/lib/ehandle.c b/lib/ehandle.c index 515e2b52..4029c0d9 100644 --- a/lib/ehandle.c +++ b/lib/ehandle.c @@ -170,7 +170,7 @@ void push_checkpoint(int mask, int value) { void push_cleanup(void (*call1)(int argc, void **argv), int mask1, void (*call2)(int argc, void **argv), int mask2, - int nargs, ...) { + unsigned int nargs, ...) { struct cleanupentry *cep; void **args; int e; diff --git a/lib/fields.c b/lib/fields.c index 386c54b3..85dc8a2f 100644 --- a/lib/fields.c +++ b/lib/fields.c @@ -31,18 +31,20 @@ static int convert_string (const char *filename, int lno, const char *what, int otherwise, FILE *warnto, int *warncount, const struct pkginfo *pigp, - const char *startp, const struct namevalue *nvip, + const char *startp, const struct namevalue *ivip, const char **endpp) { const char *ep; int c, l = 0; + struct namevalue *nvip= 0; + memcpy(&nvip,&ivip,sizeof(struct namevalue *)); ep= startp; if (!*ep) parseerr(0,filename,lno, warnto,warncount,pigp,0, _("%s is missing"),what); while (nvip->name) { if ((l= nvip->length) == 0) { l= strlen(nvip->name); - ((struct namevalue *)nvip)->length= l; + nvip->length= (const int)l; } if (strncasecmp(nvip->name,startp,l) || nvip->name[l]) nvip++; @@ -107,7 +109,7 @@ void f_filecharf(struct pkginfo *pigp, struct pkginfoperfile *pifp, fdp->name= fdp->msdosname= fdp->size= fdp->md5sum= 0; *fdpp= fdp; } - FILEFFIELD(fdp,fip->integer,char*)= cpos; + FILEFFIELD(fdp,fip->integer,const char*)= cpos; fdpp= &fdp->next; while (*space && isspace(*space)) space++; cpos= space; @@ -228,6 +230,7 @@ void f_conffiles(struct pkginfo *pigp, struct pkginfoperfile *pifp, struct conffile **lastp, *newlink; const char *endent, *endfn; int c, namelen, hashlen; + char *newptr; lastp= &pifp->conffiles; while (*value) { @@ -246,12 +249,14 @@ void f_conffiles(struct pkginfo *pigp, struct pkginfoperfile *pifp, namelen= (int)(endfn-value); if (namelen <= 0) parseerr(0,filename,lno, warnto,warncount,pigp,0, _("root or null directory is listed as a conffile")); - newlink->name= nfmalloc(namelen+2); - newlink->name[0]= '/'; - memcpy(newlink->name+1,value,namelen); - newlink->name[namelen+1]= 0; - hashlen= (int)(endent-endfn)-1; newlink->hash= nfmalloc(hashlen+1); - memcpy(newlink->hash,endfn+1,hashlen); newlink->hash[hashlen]= 0; + newptr = nfmalloc(namelen+2); + newptr[0]= '/'; + memcpy(newptr+1,value,namelen); + newptr[namelen+1]= 0; + newlink->name= newptr; + hashlen= (int)(endent-endfn)-1; newptr= nfmalloc(hashlen+1); + memcpy(newptr,endfn+1,hashlen); newptr[hashlen]= 0; + newlink->hash= newptr; newlink->next =0; *lastp= newlink; lastp= &newlink->next; diff --git a/lib/mlib.c b/lib/mlib.c index f6411931..5436424d 100644 --- a/lib/mlib.c +++ b/lib/mlib.c @@ -225,7 +225,7 @@ ssize_t buffer_read(buffer_data_t data, void *buf, ssize_t length, const char *d } #define buffer_copy_setup_dual(name, type1, name1, type2, name2) \ -inline ssize_t buffer_copy_setup_##name(type1 n1, int typeIn, void *procIn,\ +ssize_t buffer_copy_setup_##name(type1 n1, int typeIn, void *procIn,\ type2 n2, int typeOut, void *procOut,\ ssize_t limit, const char *desc, ...)\ {\ diff --git a/lib/parse.c b/lib/parse.c index 15525523..c24f983f 100644 --- a/lib/parse.c +++ b/lib/parse.c @@ -231,16 +231,16 @@ int parsedb(const char *filename, enum parsedbflags flags, &newpig.name, "package name"); if ((flags & pdb_recordavailable) || newpig.status != stat_notinstalled) { parsemustfield(0,filename,lno, warnto,warncount,&newpig,1, - &newpifp->description, "description"); + (const char **)&newpifp->description, "description"); parsemustfield(0,filename,lno, warnto,warncount,&newpig,1, - &newpifp->maintainer, "maintainer"); + (const char **)&newpifp->maintainer, "maintainer"); if (newpig.status != stat_halfinstalled) parsemustfield(0,filename,lno, warnto,warncount,&newpig,0, - (char **)&newpifp->version.version, "version"); + &newpifp->version.version, "version"); } if (flags & pdb_recordavailable) parsemustfield(0,filename,lno, warnto,warncount,&newpig,1, - &newpifp->architecture, "architecture"); + (const char **)&newpifp->architecture, "architecture"); else if (newpifp->architecture && *newpifp->architecture) newpifp->architecture= 0; diff --git a/lib/parsedump.h b/lib/parsedump.h index c964ede6..81bfc3ab 100644 --- a/lib/parsedump.h +++ b/lib/parsedump.h @@ -59,7 +59,7 @@ struct fieldinfo { const char *name; freadfunction *rcall; fwritefunction *wcall; - int integer; + unsigned int integer; }; void parseerr(FILE *file, const char *filename, int lno, FILE *warnto, int *warncount, @@ -68,7 +68,7 @@ void parseerr(FILE *file, const char *filename, int lno, FILE *warnto, int *warn void parsemustfield(FILE *file, const char *filename, int lno, FILE *warnto, int *warncount, const struct pkginfo *pigp, int warnonly, - char **value, const char *what); + const char **value, const char *what); #define MSDOS_EOF_CHAR '\032' /* ^Z */ diff --git a/lib/parsehelp.c b/lib/parsehelp.c index cb83df5d..5823615f 100644 --- a/lib/parsehelp.c +++ b/lib/parsehelp.c @@ -214,7 +214,7 @@ void parsemustfield (FILE *file, const char *filename, int lno, FILE *warnto, int *warncount, const struct pkginfo *pigp, int warnonly, - char **value, const char *what) + const char **value, const char *what) { if (!*value) { parseerr(file,filename,lno, warnto,warncount,pigp,warnonly, _("missing %s"),what); diff --git a/lib/varbuf.c b/lib/varbuf.c index e813c4a9..2dcde7ba 100644 --- a/lib/varbuf.c +++ b/lib/varbuf.c @@ -44,7 +44,7 @@ void varbufdupc(struct varbuf *v, int c, ssize_t n) { } int varbufprintf(struct varbuf *v, const char *fmt, ...) { - int ou, r; + unsigned int ou, r; va_list al; ou= v->used; @@ -62,7 +62,7 @@ int varbufprintf(struct varbuf *v, const char *fmt, ...) { } int varbufvprintf(struct varbuf *v, const char *fmt, va_list va) { - int ou, r; + unsigned int ou, r; va_list al; ou= v->used; diff --git a/lib/vercmp.c b/lib/vercmp.c index b82ef0bc..390fd538 100644 --- a/lib/vercmp.c +++ b/lib/vercmp.c @@ -32,13 +32,17 @@ int epochsdiffer(const struct versionrevision *a, return a->epoch != b->epoch; } -static int verrevcmp(const char *val, const char *ref) { +static int verrevcmp(const char *ival, const char *iref) { + static char empty[] = ""; int vc, rc; long vl, rl; - const char *vp, *rp; + char *vp, *rp; + char *val, *ref; + memcpy(&val,&ival,sizeof(char*)); + memcpy(&ref,&iref,sizeof(char*)); - if (!val) val= ""; - if (!ref) ref= ""; + if (!val) val= empty; + if (!ref) ref= empty; for (;;) { vp= val; while (*vp && !isdigit(*vp)) vp++; rp= ref; while (*rp && !isdigit(*rp)) rp++; @@ -52,8 +56,8 @@ static int verrevcmp(const char *val, const char *ref) { } val= vp; ref= rp; - vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10); - rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10); + vl=0; if (isdigit(*vp)) vl= strtol(val,&val,10); + rl=0; if (isdigit(*rp)) rl= strtol(ref,&ref,10); if (vl != rl) return vl - rl; if (!*val && !*ref) return 0; if (!*val) return -1; diff --git a/main/archives.c b/main/archives.c index ce91b63a..d73ed4ac 100644 --- a/main/archives.c +++ b/main/archives.c @@ -279,7 +279,8 @@ int tarobject(struct TarInfo *ti) { const char *usename; struct tarcontext *tc= (struct tarcontext*)ti->UserData; - int statr, fd, r, i, existingdirectory; + int statr, fd, i, existingdirectory; + size_t r; struct stat stab, stabd; char databuf[TARBLKSZ]; struct fileinlist *nifd; @@ -718,7 +719,7 @@ void check_conflict(struct dependency *dep, struct pkginfo *pkg, /* if this gets triggered, it means a package has > 10 conflicts/replaces * pairs, which is the package's fault */ - assert(cflict_index < sizeof(conflictor)); + assert(cflict_index < (int)sizeof(conflictor)); /* This conflict is OK - we'll remove the conflictor. */ conflictor[cflict_index++]= fixbyrm; varbuffree(&conflictwhy); varbuffree(&removalwhy); @@ -780,30 +781,31 @@ void archivefiles(const char *const *argv) { m_pipe(pi); if (!(fc= m_fork())) { const char *const *ap; + char **narglist; int i; m_dup2(pi[1],1); close(pi[0]); close(pi[1]); for (i=0, ap=argv; *ap; ap++, i++); - arglist= m_malloc(sizeof(char*)*(i+15)); - arglist[0]= FIND; + narglist= m_malloc(sizeof(char*)*(i+15)); + narglist[0]= strdup(FIND); for (i=1, ap=argv; *ap; ap++, i++) { if (strchr(FIND_EXPRSTARTCHARS,(*ap)[0])) { char *a; a= m_malloc(strlen(*ap)+10); strcpy(a,"./"); strcat(a,*ap); - arglist[i]= a; + narglist[i]= a; } else { - arglist[i]= *ap; + narglist[i]= strdup(*ap); } } - arglist[i++]= "-follow"; /* When editing these, make sure that */ - arglist[i++]= "-name"; /* arglist is mallocd big enough, above. */ - arglist[i++]= ARCHIVE_FILENAME_PATTERN; - arglist[i++]= "-type"; - arglist[i++]= "f"; - arglist[i++]= "-print0"; - arglist[i++]= 0; - execvp(FIND, (char* const*)arglist); + narglist[i++]= strdup("-follow"); /* When editing these, make sure that */ + narglist[i++]= strdup("-name"); /* arglist is mallocd big enough, above. */ + narglist[i++]= strdup(ARCHIVE_FILENAME_PATTERN); + narglist[i++]= strdup("-type"); + narglist[i++]= strdup("f"); + narglist[i++]= strdup("-print0"); + narglist[i++]= 0; + execvp(FIND, narglist); ohshite(_("failed to exec find for --recursive")); } close(pi[1]); diff --git a/main/configure.c b/main/configure.c index a1c2e1f0..ae766ab9 100644 --- a/main/configure.c +++ b/main/configure.c @@ -521,7 +521,7 @@ int conffderef(struct pkginfo *pkg, struct varbuf *result, const char *in) { if (result->buf[r] == '/') r++; result->used= r; debug(dbg_conffdetail,"conffderef readlink relative to `%.*s'", - result->used, result->buf); + (int)result->used, result->buf); } varbufaddstr(result,linkreadbuf); varbufaddc(result,0); diff --git a/main/enquiry.c b/main/enquiry.c index 8f8bb13d..ba9429f5 100644 --- a/main/enquiry.c +++ b/main/enquiry.c @@ -42,8 +42,8 @@ #include "main.h" int pkglistqsortcmp(const void *a, const void *b) { - struct pkginfo *pa= *(struct pkginfo**)a; - struct pkginfo *pb= *(struct pkginfo**)b; + const struct pkginfo *pa= *(const struct pkginfo**)a; + const struct pkginfo *pb= *(const struct pkginfo**)b; return strcmp(pa->name,pb->name); } @@ -176,7 +176,7 @@ static int bsyn_reinstreq(struct pkginfo *pkg, const struct badstatinfo *bsi) { static int bsyn_status(struct pkginfo *pkg, const struct badstatinfo *bsi) { if (pkg->eflag &= eflagf_reinstreq) return 0; - return pkg->status == bsi->val; + return (int)pkg->status == bsi->val; } static const struct badstatinfo badstatinfos[]= { diff --git a/main/filesdb.c b/main/filesdb.c index 209f8094..7addd7b3 100644 --- a/main/filesdb.c +++ b/main/filesdb.c @@ -589,10 +589,11 @@ struct filenamenode *findnamenode(const char *name, enum fnnflags flags) { newnode= nfmalloc(sizeof(struct filenamenode)); newnode->packages= 0; if((flags & fnn_nocopy) && name > orig_name && name[-1] == '/') - newnode->name = (char *)name - 1; + newnode->name = name - 1; else { - newnode->name= nfmalloc(strlen(name)+2); - newnode->name[0]= '/'; strcpy(newnode->name+1,name); + char *newname= nfmalloc(strlen(name)+2); + newname[0]= '/'; strcpy(newname+1,name); + newnode->name= newname; } newnode->flags= 0; newnode->next= 0; diff --git a/main/filesdb.h b/main/filesdb.h index e50d7407..02c76fa5 100644 --- a/main/filesdb.h +++ b/main/filesdb.h @@ -54,7 +54,7 @@ enum fnnflags { struct filenamenode { struct filenamenode *next; - char *name; + const char *name; struct filepackages *packages; struct diversion *divert; struct filestatoverride *statoverride; diff --git a/main/help.c b/main/help.c index 561a14a1..fce0d8bf 100644 --- a/main/help.c +++ b/main/help.c @@ -173,7 +173,7 @@ static const char* preexecscript(const char *path, char *const *argv) { * none of the stuff here will work if admindir isn't inside instdir * as expected. - fixme */ - int instdirl; + size_t instdirl; if (*instdir) { if (chroot(instdir)) ohshite(_("failed to chroot to `%.250s'"),instdir); @@ -195,7 +195,8 @@ static char *const *vbuildarglist(const char *scriptname, va_list ap) { int i; i=0; - bufs[i++]= (char*)scriptname; /* yes, cast away const because exec wants it that way */ + if(bufs[0]) free(bufs[0]); + bufs[i++]= strdup(scriptname); /* yes, cast away const because exec wants it that way */ for (;;) { assert(i < PKGSCRIPTMAXARGS); nextarg= va_arg(ap,char*); @@ -215,7 +216,7 @@ static char *const *buildarglist(const char *scriptname, ...) { return arglist; } -#define NSCRIPTCATCHSIGNALS sizeof(script_catchsignallist)/sizeof(int)-1 +#define NSCRIPTCATCHSIGNALS (int)(sizeof(script_catchsignallist)/sizeof(int)-1) static int script_catchsignallist[]= { SIGQUIT, SIGINT, 0 }; static struct sigaction script_uncatchsignal[NSCRIPTCATCHSIGNALS]; @@ -252,8 +253,7 @@ static void setexecute(const char *path, struct stat *stab) { if (!chmod(path,0755)) return; ohshite(_("unable to set execute permissions on `%.250s'"),path); } -static int do_script(const char *pkg, const char *scriptname, const char *scriptpath, struct stat *stab, char *const *arglist, const char *desc, const char *name, int warn) { - const char *scriptexec; +static int do_script(const char *pkg, const char *scriptname, const char *scriptpath, struct stat *stab, char *const arglist[], const char *desc, const char *name, int warn) { int c1, r; setexecute(scriptpath,stab); @@ -264,9 +264,8 @@ static int do_script(const char *pkg, const char *scriptname, const char *script narglist=nfmalloc(r*sizeof(char*)); for (r=1; arglist[r]; r++) narglist[r]= arglist[r]; - scriptexec= preexecscript(scriptpath,arglist); - narglist[0]= (char*)scriptexec; - execv(scriptexec,arglist); + narglist[0]= strdup(preexecscript(scriptpath,arglist)); + execv(narglist[0],narglist); ohshite(desc,name); } script_catchsignals(); /* This does a push_cleanup() */ @@ -423,7 +422,7 @@ int isdirectoryinuse(struct filenamenode *file, struct pkginfo *pkg) { return 0; } -void oldconffsetflags(struct conffile *searchconff) { +void oldconffsetflags(const struct conffile *searchconff) { struct filenamenode *namenode; while (searchconff) { diff --git a/main/main.c b/main/main.c index 94da90df..50481f22 100644 --- a/main/main.c +++ b/main/main.c @@ -284,7 +284,7 @@ static void setstatuspipe(const struct cmdinfo *cip, const char *value) { void setforce(const struct cmdinfo *cip, const char *value) { const char *comma; - int l; + size_t l; const struct forceinfo *fip; if (!strcmp(value,"help")) { @@ -333,7 +333,7 @@ Forcing options marked [*] are enabled by default.\n"), for (fip=forceinfos; fip->name; fip++) *fip->opt= cip->arg; else - badusage(_("unknown force/refuse option `%.*s'"), l<250 ? l : 250, value); + badusage(_("unknown force/refuse option `%.*s'"), l<250 ? (int)l : 250, value); else *fip->opt= cip->arg; if (!comma) break; @@ -422,7 +422,13 @@ static const struct cmdinfo cmdinfos[]= { static void execbackend(int argc, const char *const *argv) NONRETURNING; static void execbackend(int argc, const char *const *argv) { - execvp(BACKEND, (char* const*) argv); + char **nargv= malloc(sizeof(char *) * argc + 1); + int i= 0; + if (!nargv) ohshite(_("couldn't malloc in execbackend")); + while (i < argc) + nargv[i++]= strdup(argv[i]); + nargv[i]= 0; + execvp(BACKEND, nargv); ohshite(_("failed to exec dpkg-deb")); } void commandfd(const char *const *argv) { @@ -468,7 +474,7 @@ void commandfd(const char *const *argv) { if (c == EOF) ohshit(_("unexpected eof before end of line %d"),lno); if (!argc) continue; varbufaddc(&linevb,0); -printf("line=`%*s'\n",linevb.used,linevb.buf); +printf("line=`%*s'\n",(int)linevb.used,linevb.buf); oldargs= newargs= realloc(oldargs,sizeof(const char *) * (argc + 1)); argc= 1; ptr= linevb.buf; diff --git a/main/main.h b/main/main.h index f56107ed..44935bc0 100644 --- a/main/main.h +++ b/main/main.h @@ -175,7 +175,7 @@ int force_conff_miss(struct deppossi *possi); int force_conflicts(struct deppossi *possi); void ensure_package_clientdata(struct pkginfo *pkg); const char *pkgadminfile(struct pkginfo *pkg, const char *whichfile); -void oldconffsetflags(struct conffile *searchconff); +void oldconffsetflags(const struct conffile *searchconff); void ensure_pathname_nonexisting(const char *pathname); int chmodsafe_unlink(const char *pathname); /* chmod 600, then unlink */ void checkpath(void); diff --git a/main/packages.c b/main/packages.c index 4085936f..c293b349 100644 --- a/main/packages.c +++ b/main/packages.c @@ -65,7 +65,7 @@ void packages(const char *const *argv) { struct pkgiterator *it; struct pkginfo *pkg; const char *thisarg; - int l; + size_t l; modstatdb_init(admindir, f_noact ? msdbrw_readonly @@ -409,6 +409,6 @@ int dependencies_ok(struct pkginfo *pkg, struct pkginfo *removing, ok= 1; varbuffree(&oemsgs); - debug(dbg_depcon,"ok %d msgs >>%.*s<<", ok, aemsgs->used, aemsgs->buf); + debug(dbg_depcon,"ok %d msgs >>%.*s<<", ok, (int)aemsgs->used, aemsgs->buf); return ok; } diff --git a/main/processarc.c b/main/processarc.c index 5f37158e..070737cd 100644 --- a/main/processarc.c +++ b/main/processarc.c @@ -670,7 +670,7 @@ void process_archive(const char *filename) { debug(dbg_veryverbose, "process_archive info file `%s'", de->d_name); if (de->d_name[0] == '.') continue; /* ignore dotfiles, including `.' and `..' */ p= strrchr(de->d_name,'.'); if (!p) continue; /* ignore anything odd */ - if (strlen(pkg->name) != p-de->d_name || + if (strlen(pkg->name) != (size_t)(p-de->d_name) || strncmp(de->d_name,pkg->name,p-de->d_name)) continue; debug(dbg_stupidlyverbose, "process_archive info this pkg"); /* Right do we have one ? */ @@ -908,7 +908,7 @@ void process_archive(const char *filename) { debug(dbg_veryverbose, "process_archive info file `%s'", de->d_name); if (de->d_name[0] == '.') continue; p= strrchr(de->d_name,'.'); if (!p) continue; - if (strlen(otherpkg->name) != p-de->d_name || + if (strlen(otherpkg->name) != (size_t)(p-de->d_name) || strncmp(de->d_name,otherpkg->name,p-de->d_name)) continue; debug(dbg_stupidlyverbose, "process_archive info this pkg"); fnvb.used= infodirbaseused; diff --git a/main/remove.c b/main/remove.c index 0e6658d7..c83453a8 100644 --- a/main/remove.c +++ b/main/remove.c @@ -294,7 +294,7 @@ void removal_bulk(struct pkginfo *pkg) { debug(dbg_veryverbose, "removal_bulk info file `%s'", de->d_name); if (de->d_name[0] == '.') continue; p= strrchr(de->d_name,'.'); if (!p) continue; - if (strlen(pkg->name) != p-de->d_name || + if (strlen(pkg->name) != (size_t)(p-de->d_name) || strncmp(de->d_name,pkg->name,p-de->d_name)) continue; debug(dbg_stupidlyverbose, "removal_bulk info this pkg"); /* We need the postrm and list files for --purge. */ @@ -366,7 +366,7 @@ void removal_bulk(struct pkginfo *pkg) { *lconffp= conff->next; } else { debug(dbg_conffdetail,"removal_bulk set to new conffile `%s'",conff->name); - conff->hash= (char*)NEWCONFFILEFLAG; /* yes, cast away const */ + conff->hash= NEWCONFFILEFLAG; /* yes, cast away const */ } } modstatdb_note(pkg); diff --git a/split/dpkg-split.h b/split/dpkg-split.h index 7caee533..1219052f 100644 --- a/split/dpkg-split.h +++ b/split/dpkg-split.h @@ -32,12 +32,12 @@ struct partinfo { const char *version; const char *md5sum; unsigned long orglength; - int thispartn, maxpartn; + unsigned int thispartn, maxpartn; unsigned long maxpartlen; unsigned long thispartoffset; - unsigned long thispartlen; - unsigned long headerlen; /* size of header in part file */ - unsigned long filesize; + size_t thispartlen; + size_t headerlen; /* size of header in part file */ + off_t filesize; }; struct partqueue { diff --git a/split/info.c b/split/info.c index 50197d7a..e0e4aa02 100644 --- a/split/info.c +++ b/split/info.c @@ -74,9 +74,10 @@ static char *nextline(char **ripp, const char *fn, const char *what) { struct partinfo *read_info(FILE *partfile, const char *fn, struct partinfo *ir) { /* returns info (nfmalloc'd) if was an archive part and we read it, 0 if it wasn't */ static char *readinfobuf= 0; - static int readinfobuflen= 0; + static size_t readinfobuflen= 0; - unsigned long thisilen, templong; + size_t thisilen; + unsigned int templong; char magicbuf[sizeof(PARTMAGIC)-1], *rip, *partnums, *slash; struct ar_hdr arh; int c; diff --git a/split/join.c b/split/join.c index 69993df4..6521c03f 100644 --- a/split/join.c +++ b/split/join.c @@ -34,8 +34,8 @@ void reassemble(struct partinfo **partlist, const char *outputfile) { FILE *output, *input; void *buffer; struct partinfo *pi; - int i,nr; - long buffersize; + unsigned int i; + size_t nr,buffersize; printf("Putting package %s together from %d parts: ", partlist[0]->package,partlist[0]->maxpartn); @@ -96,7 +96,7 @@ void do_join(const char *const *argv) { const char *thisarg; struct partqueue *pq; struct partinfo *refi, *pi, **partlist; - int i; + unsigned int i; assert(!queue); if (!*argv) badusage(_("--join requires one or more part file arguments")); diff --git a/split/main.c b/split/main.c index 349aa1d9..3f94a3cf 100644 --- a/split/main.c +++ b/split/main.c @@ -143,7 +143,7 @@ static void setaction(const struct cmdinfo *cip, const char *value) { if (cipaction) badusage(_("conflicting actions --%s and --%s"),cip->olong,cipaction->olong); cipaction= cip; - assert(cip-cmdinfos < sizeof(dofunctions)*sizeof(dofunction*)); + assert((int)(cip-cmdinfos) < (int)(sizeof(dofunctions)*sizeof(dofunction*))); action= dofunctions[cip-cmdinfos]; } diff --git a/split/queue.c b/split/queue.c index a7f2cc64..c41772b8 100644 --- a/split/queue.c +++ b/split/queue.c @@ -97,7 +97,9 @@ void do_auto(const char *const *argv) { const char *partfile; struct partinfo *pi, *refi, *npi, **partlist, *otherthispart; struct partqueue *pq; - int i, nr, j, ap; + unsigned int i, j; + int ap; + long nr; FILE *part; void *buffer; char *p, *q; @@ -187,7 +189,7 @@ void do_queue(const char *const *argv) { const char *head; struct stat stab; unsigned long bytes; - int i; + unsigned int i; if (*argv) badusage(_("--listq does not take any arguments")); scandepot(); diff --git a/utils/md5sum.c b/utils/md5sum.c index b84c430d..68fe8c71 100644 --- a/utils/md5sum.c +++ b/utils/md5sum.c @@ -218,7 +218,7 @@ do_check(FILE *chkf) unsigned char chk_digest[16], file_digest[16]; char filename[256]; FILE *fp; - int flen = 14; + size_t flen = 14; while ((rc = get_md5_line(chkf, chk_digest, filename)) >= 0) { if (rc == 0) /* not an md5 line */ @@ -226,7 +226,7 @@ do_check(FILE *chkf) if (verbose) { if (strlen(filename) > flen) flen = strlen(filename); - fprintf(stderr, "%-*s ", flen, filename); + fprintf(stderr, "%-*s ", (int)flen, filename); } if (bin_mode || rc == 2) fp = fopen(filename, FOPRBIN); diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c index 6f9b541d..452526a2 100644 --- a/utils/start-stop-daemon.c +++ b/utils/start-stop-daemon.c @@ -134,7 +134,7 @@ static void *xmalloc(int size); static void push(struct pid_list **list, int pid); static void do_help(void); static void parse_options(int argc, char * const *argv); -static int pid_is_user(int pid, int uid); +static int pid_is_user(int pid, uid_t uid); static int pid_is_cmd(int pid, const char *name); static void check(int pid); static void do_pidfile(const char *name); @@ -338,7 +338,7 @@ static int parse_integer (const char *string, int *value_r) { static int parse_signal (const char *signal_str, int *signal_nr) { - int i; + unsigned int i; if (parse_integer(signal_str, signal_nr) == 0) return 0; @@ -403,7 +403,7 @@ parse_schedule(const char *schedule_str) { while (schedule_str != NULL) { slash = strchr(schedule_str,'/'); str_len = slash ? slash - schedule_str : strlen(schedule_str); - if (str_len >= sizeof(item_buf)) + if (str_len >= (ptrdiff_t)sizeof(item_buf)) badusage("invalid schedule item: far too long" " (you must delimit items with slashes)"); memcpy(item_buf, schedule_str, str_len); @@ -577,7 +577,7 @@ pid_is_exec(int pid, const struct stat *esb) static int -pid_is_user(int pid, int uid) +pid_is_user(int pid, uid_t uid) { struct stat sb; char buf[32]; -- 2.39.5