Add new function zip_stat_init to initialize a struct zip_stat and use it in source callbacks. Fixes uninitialized encryption_method members. --HG-- branch : HEAD
diff --git a/lib/Makefile.am b/lib/Makefile.am index 3530014..843e481 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am
@@ -50,6 +50,7 @@ zip_set_name.c \ zip_stat.c \ zip_stat_index.c \ + zip_stat_init.c \ zip_strerror.c \ zip_unchange.c \ zip_unchange_all.c \
diff --git a/lib/zip.h b/lib/zip.h index 9cb7a92..9fe5c1b 100644 --- a/lib/zip.h +++ b/lib/zip.h
@@ -2,7 +2,7 @@ #define _HAD_ZIP_H /* - $NiH: zip.h,v 1.58 2006/10/03 12:23:13 dillo Exp $ + $NiH: zip.h,v 1.59 2006/10/04 15:21:09 dillo Exp $ zip.h -- exported declarations. Copyright (C) 1999-2006 Dieter Baron and Thomas Klausner @@ -194,6 +194,7 @@ off_t, off_t); int zip_stat(struct zip *, const char *, int, struct zip_stat *); int zip_stat_index(struct zip *, int, int, struct zip_stat *); +void zip_stat_init(struct zip_stat *); const char *zip_strerror(struct zip *); int zip_unchange(struct zip *, int); int zip_unchange_all(struct zip *);
diff --git a/lib/zip_source_buffer.c b/lib/zip_source_buffer.c index 39f5895..f76515c 100644 --- a/lib/zip_source_buffer.c +++ b/lib/zip_source_buffer.c
@@ -1,8 +1,8 @@ /* - $NiH: zip_source_buffer.c,v 1.7 2006/02/22 19:52:20 dillo Exp $ + $NiH: zip_source_buffer.c,v 1.8 2006/04/23 14:50:49 wiz Exp $ zip_source_buffer.c -- create zip data source from buffer - Copyright (C) 1999, 2003, 2004, 2005 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2006 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at <nih@giga.or.at> @@ -125,11 +125,9 @@ st = (struct zip_stat *)data; + zip_stat_init(st); st->mtime = z->mtime; - st->crc = 0; st->size = z->end - z->data; - st->comp_size = -1; - st->comp_method = ZIP_CM_STORE; return sizeof(*st); }
diff --git a/lib/zip_source_filep.c b/lib/zip_source_filep.c index 2737273..32d2897 100644 --- a/lib/zip_source_filep.c +++ b/lib/zip_source_filep.c
@@ -1,5 +1,5 @@ /* - $NiH: zip_source_filep.c,v 1.5 2005/05/20 22:05:30 wiz Exp $ + $NiH: zip_source_filep.c,v 1.6 2005/06/09 19:57:10 dillo Exp $ zip_source_filep.c -- create data source from FILE * Copyright (C) 1999, 2003, 2004, 2005 Dieter Baron and Thomas Klausner @@ -138,24 +138,20 @@ if (len < sizeof(*st)) return -1; - st = (struct zip_stat *)data; - if (fstat(fileno(z->f), &fst) != 0) { z->e[0] = ZIP_ER_READ; /* best match */ z->e[1] = errno; return -1; } + st = (struct zip_stat *)data; + + zip_stat_init(st); st->mtime = fst.st_mtime; - st->crc = 0; if (z->len != -1) st->size = z->len; else if ((fst.st_mode&S_IFMT) == S_IFREG) st->size = fst.st_size; - else - st->size = -1; - st->comp_size = -1; - st->comp_method = ZIP_CM_STORE; return sizeof(*st); }
diff --git a/lib/zip_stat_init.c b/lib/zip_stat_init.c new file mode 100644 index 0000000..a7d0a1f --- /dev/null +++ b/lib/zip_stat_init.c
@@ -0,0 +1,53 @@ +/* + $NiH$ + + zip_stat_init.c -- initialize struct zip_stat. + Copyright (C) 2006 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at <nih@giga.or.at> + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + + +#include "zipint.h" + + + +void +zip_stat_init(struct zip_stat *st) +{ + st->name = NULL; + st->index = -1; + st->crc = 0; + st->mtime = (time_t)-1; + st->size = -1; + st->comp_size = -1; + st->comp_method = ZIP_CM_STORE; + st->encryption_method = ZIP_EM_NONE; +}