From: Adam Heath Date: Sat, 21 Apr 2001 22:22:42 +0000 (+0000) Subject: * main/help.c, main/processarc.c, main/filesdb.c, main/configure.c, X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=95e4aed8a7c445e933f64e05481ea613dc5697f5;p=dpkg * main/help.c, main/processarc.c, main/filesdb.c, main/configure.c, main/archives.c, lib/parse.c: Fix int/pointer casting warnings. * include/dpkg.h.in, lib/mlib.c: Rewrote buffer_copy_setup, to avoid int/pointer casting warnings. These means there are several variations of buffer_copy_setup. Also, converted the desc parameter to const. --- diff --git a/ChangeLog b/ChangeLog index 9f0724b1..4fb8afd0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Sat Apr 21 17:16:28 CDT 2001 Adam Heath + + * main/help.c, main/processarc.c, main/filesdb.c, main/configure.c, + main/archives.c, lib/parse.c: Fix int/pointer casting warnings. + * include/dpkg.h.in, lib/mlib.c: Rewrote buffer_copy_setup, to avoid + int/pointer casting warnings. These means there are several + variations of buffer_copy_setup. Also, converted the desc parameter + to const. + Sun Apr 22 00:09:58 CEST 2001 Wichert Akkerman * optlib/long-options.c, lib/showcright.c: include stdlib.h to get diff --git a/include/dpkg.h.in b/include/dpkg.h.in index 417f0d3d..14e5eab2 100644 --- a/include/dpkg.h.in +++ b/include/dpkg.h.in @@ -213,56 +213,72 @@ int waitsubproc(pid_t pid, const char *description, int sigpipeok, int warn); #define BUFFER_READ_SHUTDOWN 1 << 19 typedef struct buffer_data *buffer_data_t; -typedef ssize_t (*buffer_proc_t)(buffer_data_t data, void *buf, ssize_t size, char *desc); +typedef ssize_t (*buffer_proc_t)(buffer_data_t data, void *buf, ssize_t size, const char *desc); +typedef union buffer_arg { + void *ptr; + int i; +} buffer_arg; + struct buffer_data { buffer_proc_t proc; - void *data; + buffer_arg data; int type; }; #define fd_md5(fd, hash, limit, desc...)\ - buffer_copy_setup((void *)fd, BUFFER_READ_FD, NULL, \ - hash, BUFFER_WRITE_MD5, NULL, \ - limit, desc) + buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \ + hash, BUFFER_WRITE_MD5, NULL, \ + limit, desc) #define stream_md5(file, hash, limit, desc...)\ - buffer_copy_setup((void *)file, BUFFER_READ_STREAM, NULL, \ - hash, BUFFER_WRITE_MD5, NULL, \ - limit, desc) - + buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \ + hash, BUFFER_WRITE_MD5, NULL, \ + limit, desc) #define fd_fd_copy(fd1, fd2, limit, desc...)\ - buffer_copy_setup((void *)fd1, BUFFER_READ_FD, NULL, \ - (void *)fd2, BUFFER_WRITE_FD, NULL, \ - limit, desc) + buffer_copy_setup_IntInt(fd1, BUFFER_READ_FD, NULL, \ + fd2, BUFFER_WRITE_FD, NULL, \ + limit, desc) #define fd_buf_copy(fd, buf, limit, desc...)\ - buffer_copy_setup((void *)fd, BUFFER_READ_FD, NULL, \ - buf, BUFFER_WRITE_BUF, NULL, \ - limit, desc) + buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \ + buf, BUFFER_WRITE_BUF, NULL, \ + limit, desc) #define fd_vbuf_copy(fd, buf, limit, desc...)\ - buffer_copy_setup((void *)fd, BUFFER_READ_FD, NULL, \ - buf, BUFFER_WRITE_VBUF, NULL, \ - limit, desc) + buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \ + buf, BUFFER_WRITE_VBUF, NULL, \ + limit, desc) #define fd_null_copy(fd, limit, desc...) \ if (lseek(fd, limit, SEEK_CUR) == -1) { \ if(errno != ESPIPE) ohshite(desc); \ - buffer_copy_setup((void *)fd, BUFFER_READ_FD, NULL, \ - 0, BUFFER_WRITE_NULL, NULL, \ - limit, desc);\ + buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \ + 0, BUFFER_WRITE_NULL, NULL, \ + limit, desc);\ } #define stream_null_copy(file, limit, desc...) \ if (fseek(file, limit, SEEK_CUR) == -1) { \ if(errno != EBADF) ohshite(desc); \ - buffer_copy_setup((void *)file, BUFFER_READ_STREAM, NULL, \ - 0, BUFFER_WRITE_NULL, NULL, \ - limit, desc);\ + buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \ + 0, BUFFER_WRITE_NULL, NULL, \ + limit, desc);\ } #define stream_fd_copy(file, fd, limit, desc...)\ - buffer_copy_setup((void *)file, BUFFER_READ_STREAM, NULL, \ - (void *)fd, BUFFER_WRITE_FD, NULL, \ - limit, desc) -ssize_t buffer_copy_setup(void *argIn, int typeIn, void *procIn, - void *argOut, int typeOut, void *procOut, - ssize_t limit, const char *desc, ...); -ssize_t buffer_copy(buffer_data_t read_data, buffer_data_t write_data, ssize_t limit, char *desc); + 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, + 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, + 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, + 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, + int i2, int typeOut, void *procOut, + ssize_t limit, const char *desc, ...); +ssize_t buffer_copy_setup(buffer_arg argIn, int typeIn, void *procIn, + buffer_arg argOut, int typeOut, void *procOut, + ssize_t limit, const char *desc); +ssize_t buffer_copy(buffer_data_t read_data, buffer_data_t write_data, ssize_t limit, const char *desc); extern volatile int onerr_abort; diff --git a/lib/mlib.c b/lib/mlib.c index b7b8cca5..a0f10e5b 100644 --- a/lib/mlib.c +++ b/lib/mlib.c @@ -133,15 +133,15 @@ int waitsubproc(pid_t pid, const char *description, int sigpipeok, int warn) { return checksubprocerr(status,description,sigpipeok, warn); } -ssize_t buffer_write(buffer_data_t data, void *buf, ssize_t length, char *desc) { +ssize_t buffer_write(buffer_data_t data, void *buf, ssize_t length, const char *desc) { ssize_t ret= length; if(data->type & BUFFER_WRITE_SETUP) { switch(data->type ^ BUFFER_WRITE_SETUP) { case BUFFER_WRITE_MD5: { - unsigned char *hash= data->data; + unsigned char *hash= data->data.ptr; void ** array= malloc(sizeof(void *) * 2); - data->data= array; + data->data.ptr= array; array[0]= hash; array[1]= malloc(sizeof(struct MD5Context)); MD5Init((struct MD5Context *)array[1]); @@ -156,8 +156,8 @@ ssize_t buffer_write(buffer_data_t data, void *buf, ssize_t length, char *desc) { int i; unsigned char digest[16], *p = digest; - unsigned char *hash= (unsigned char *)((void **)data->data)[0]; - MD5Final(digest, (struct MD5Context *)((void **)data->data)[1]); + unsigned char *hash= (unsigned char *)((void **)data->data.ptr)[0]; + MD5Final(digest, (struct MD5Context *)((void **)data->data.ptr)[1]); for (i = 0; i < 16; ++i) { sprintf(hash, "%02x", *p++); hash += 2; @@ -169,27 +169,27 @@ ssize_t buffer_write(buffer_data_t data, void *buf, ssize_t length, char *desc) } switch(data->type) { case BUFFER_WRITE_BUF: - memcpy(data->data, buf, length); - (char*)data->data += length; + memcpy(data->data.ptr, buf, length); + (char*)data->data.ptr += length; break; case BUFFER_WRITE_VBUF: - varbufaddbuf((struct varbuf *)data->data, buf, length); + varbufaddbuf((struct varbuf *)data->data.ptr, buf, length); break; case BUFFER_WRITE_FD: - if((ret= write((int)data->data, buf, length)) < 0 && errno != EINTR) - ohshite(_("failed in buffer_write(fd) (%i, ret=%i, %s)"), (int)data->data, ret, desc); + if((ret= write(data->data.i, buf, length)) < 0 && errno != EINTR) + ohshite(_("failed in buffer_write(fd) (%i, ret=%zi %s)"), data->data.i, ret, desc); break; case BUFFER_WRITE_NULL: break; case BUFFER_WRITE_STREAM: - ret= fwrite(buf, 1, length, (FILE *)data->data); - if(feof((FILE *)data->data)) + ret= fwrite(buf, 1, length, (FILE *)data->data.ptr); + if(feof((FILE *)data->data.ptr)) ohshite(_("eof in buffer_write(stream): %s"), desc); - if(ferror((FILE *)data->data)) + if(ferror((FILE *)data->data.ptr)) ohshite(_("error in buffer_write(stream): %s"), desc); break; case BUFFER_WRITE_MD5: - MD5Update((struct MD5Context *)((void **)data->data)[1], buf, length); + MD5Update((struct MD5Context *)((void **)data->data.ptr)[1], buf, length); break; default: fprintf(stderr, _("unknown data type `%i' in buffer_write\n"), data->type); @@ -197,7 +197,7 @@ ssize_t buffer_write(buffer_data_t data, void *buf, ssize_t length, char *desc) return ret; } -ssize_t buffer_read(buffer_data_t data, void *buf, ssize_t length, char *desc) { +ssize_t buffer_read(buffer_data_t data, void *buf, ssize_t length, const char *desc) { ssize_t ret= length; if(data->type & BUFFER_READ_SETUP) { return 0; @@ -207,14 +207,14 @@ ssize_t buffer_read(buffer_data_t data, void *buf, ssize_t length, char *desc) { } switch(data->type) { case BUFFER_READ_FD: - if((ret= read((int)data->data, buf, length)) < 0 && errno != EINTR) + if((ret= read(data->data.i, buf, length)) < 0 && errno != EINTR) ohshite(_("failed in buffer_read(fd): %s"), desc); break; case BUFFER_READ_STREAM: - ret= fread(buf, 1, length, (FILE *)data->data); - if(feof((FILE *)data->data)) + ret= fread(buf, 1, length, (FILE *)data->data.ptr); + if(feof((FILE *)data->data.ptr)) return ret; - if(ferror((FILE *)data->data)) + if(ferror((FILE *)data->data.ptr)) ohshite(_("error in buffer_read(stream): %s"), desc); break; default: @@ -223,42 +223,59 @@ ssize_t buffer_read(buffer_data_t data, void *buf, ssize_t length, char *desc) { return ret; } -ssize_t buffer_copy_setup(void *argIn, int typeIn, void *procIn, - void *argOut, int typeOut, void *procOut, - ssize_t limit, const char *desc, ...) +#define buffer_copy_setup_dual(name, type1, name1, type2, name2) \ +inline ssize_t buffer_copy_setup_##name(type1 n1, int typeIn, void *procIn,\ + type2 n2, int typeOut, void *procOut,\ + ssize_t limit, const char *desc, ...)\ +{\ + va_list al;\ + buffer_arg a1, a2;\ + struct varbuf v;\ + ssize_t ret;\ + a1.name1 = n1; a2.name2 = n2;\ + varbufinit(&v);\ + va_start(al,desc);\ + varbufvprintf(&v, desc, al);\ + va_end(al);\ + ret = buffer_copy_setup(a1, typeIn, procIn,\ + a2, typeOut, procOut,\ + limit, v.buf);\ + varbuffree(&v);\ + return ret;\ +} + +buffer_copy_setup_dual(IntInt, int, i, int, i); +buffer_copy_setup_dual(IntPtr, int, i, void *, ptr); +buffer_copy_setup_dual(PtrInt, void *, ptr, int, i); +buffer_copy_setup_dual(PtrPtr, void *, ptr, void *, ptr); + +ssize_t buffer_copy_setup(buffer_arg argIn, int typeIn, void *procIn, + buffer_arg argOut, int typeOut, void *procOut, + ssize_t limit, const char *desc) { struct buffer_data read_data = { procIn, argIn, typeIn }, write_data = { procOut, argOut, typeOut }; - va_list al; - struct varbuf v; ssize_t ret; - varbufinit(&v); - - va_start(al,desc); - varbufvprintf(&v, desc, al); - va_end(al); - if ( procIn == NULL ) read_data.proc = buffer_read; if ( procOut == NULL ) write_data.proc = buffer_write; read_data.type |= BUFFER_READ_SETUP; - read_data.proc(&read_data, NULL, 0, v.buf); + read_data.proc(&read_data, NULL, 0, desc); read_data.type = typeIn; write_data.type |= BUFFER_WRITE_SETUP; - write_data.proc(&write_data, NULL, 0, v.buf); + write_data.proc(&write_data, NULL, 0, desc); write_data.type = typeOut; - ret = buffer_copy(&read_data, &write_data, limit, v.buf); + ret = buffer_copy(&read_data, &write_data, limit, desc); write_data.type |= BUFFER_WRITE_SHUTDOWN; - write_data.proc(&write_data, NULL, 0, v.buf); + write_data.proc(&write_data, NULL, 0, desc); read_data.type |= BUFFER_READ_SHUTDOWN; - read_data.proc(&read_data, NULL, 0, v.buf); - varbuffree(&v); + read_data.proc(&read_data, NULL, 0, desc); return ret; } -ssize_t buffer_copy(buffer_data_t read_data, buffer_data_t write_data, ssize_t limit, char *desc) { +ssize_t buffer_copy(buffer_data_t read_data, buffer_data_t write_data, ssize_t limit, const char *desc) { char *buf, *writebuf; long bytesread= 0, byteswritten= 0; int bufsize= 32768; diff --git a/lib/parse.c b/lib/parse.c index 4e0d3d82..98b231e8 100644 --- a/lib/parse.c +++ b/lib/parse.c @@ -74,7 +74,7 @@ const struct fieldinfo fieldinfos[]= { #define NFIELDS (sizeof(fieldinfos)/sizeof(struct fieldinfo)) const int nfields= NFIELDS; -static void cu_parsedb(int argc, void **argv) { close((int)*argv); } +static void cu_parsedb(int argc, void **argv) { close(*(int *)argv); } int parsedb(const char *filename, enum parsedbflags flags, struct pkginfo **donep, FILE *warnto, int *warncount) { @@ -103,7 +103,7 @@ int parsedb(const char *filename, enum parsedbflags flags, fd= open(filename, O_RDONLY); if (fd == -1) ohshite(_("failed to open package info file `%.255s' for reading"),filename); - push_cleanup(cu_parsedb,~0, 0,0, 1,(void*)fd); + push_cleanup(cu_parsedb,~0, 0,0, 1,&fd); if (fstat(fd, &stat) == -1) ohshite(_("can't stat package info file `%.255s'"),filename); diff --git a/main/archives.c b/main/archives.c index 0b601c27..ce91b63a 100644 --- a/main/archives.c +++ b/main/archives.c @@ -461,7 +461,7 @@ int tarobject(struct TarInfo *ti) { */ fd= open(fnamenewvb.buf, (O_CREAT|O_EXCL|O_WRONLY), 0); if (fd < 0) ohshite(_("unable to create `%.255s'"),ti->Name); - push_cleanup(cu_closefd,ehflag_bombout, 0,0, 1,(void*)fd); + push_cleanup(cu_closefd,ehflag_bombout, 0,0, 1,&fd); debug(dbg_eachfiledetail,"tarobject NormalFile[01] open size=%lu", (unsigned long)ti->Size); { char fnamebuf[256]; diff --git a/main/configure.c b/main/configure.c index 2b83eb69..a1c2e1f0 100644 --- a/main/configure.c +++ b/main/configure.c @@ -539,7 +539,7 @@ static void md5hash(struct pkginfo *pkg, char hashbuf[33], const char *fn) { fd= open(fn,O_RDONLY); if (fd >= 0) { - push_cleanup(cu_closefd,ehflag_bombout, 0,0, 1,(void*)&fd); + push_cleanup(cu_closefd,ehflag_bombout, 0,0, 1,&fd); fd_md5(fd, hashbuf, -1, _("md5hash")); pop_cleanup(ehflag_normaltidy); /* fd= open(cdr.buf) */ close(fd); diff --git a/main/filesdb.c b/main/filesdb.c index 996c4bf7..342aa6e8 100644 --- a/main/filesdb.c +++ b/main/filesdb.c @@ -135,7 +135,7 @@ void ensure_packagefiles_available(struct pkginfo *pkg) { return; } - push_cleanup(cu_closefd,ehflag_bombout, 0,0, 1,(void*)fd); + push_cleanup(cu_closefd,ehflag_bombout, 0,0, 1,&fd); if(fstat(fd, &stat_buf)) ohshite("unable to stat files list file for package `%.250s'",pkg->name); diff --git a/main/help.c b/main/help.c index 5f5f4912..5919dadf 100644 --- a/main/help.c +++ b/main/help.c @@ -135,8 +135,8 @@ void cu_closedir(int argc, void **argv) { } void cu_closefd(int argc, void **argv) { - int *ip= (int*)(argv[0]); - close(*ip); + int ip= *(int*)argv; + close(ip); } int ignore_depends(struct pkginfo *pkg) { diff --git a/main/processarc.c b/main/processarc.c index 516a4c52..2f649d20 100644 --- a/main/processarc.c +++ b/main/processarc.c @@ -539,7 +539,7 @@ void process_archive(const char *filename) { push_cleanup(cu_fileslist,~0, 0, 0, 0); tc.pkg= pkg; tc.backendpipe= p1[0]; - push_cleanup(cu_closefd,~ehflag_bombout, 0,0, 1,(void*)&tc.backendpipe); + push_cleanup(cu_closefd,~ehflag_bombout, 0,0, 1,&tc.backendpipe); r= TarExtractor((void*)&tc, &tf); if (r) {