PERFORCE change 145391 for review
Anselm Strauss
strauss at FreeBSD.org
Thu Jul 17 21:00:35 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=145391
Change 145391 by strauss at strauss_marvelman on 2008/07/17 20:59:42
Never mix up static and automatic storage duration
Affected files ...
.. //depot/projects/soc2008/strauss_libarchive/libarchive/archive_write_set_format_zip.c#11 edit
Differences ...
==== //depot/projects/soc2008/strauss_libarchive/libarchive/archive_write_set_format_zip.c#11 (text+ko) ====
@@ -97,15 +97,20 @@
archive_write_set_format_zip(struct archive *_a)
{
struct archive_write *a = (struct archive_write *)_a;
- struct zip zip;
+ struct zip *zip;
/* If another format was already registered, unregister it. */
if (a->format_destroy != NULL)
(a->format_destroy)(a);
+
+ zip = (struct zip *) malloc(sizeof(*zip));
+ if (zip == NULL) {
+ archive_set_error(&a->archive, ENOMEM, "Can't allocate zip data");
+ return (ARCHIVE_FATAL);
+ }
+ zip->central_directory = NULL;
+ a->format_data = zip;
- zip->central_directory = NULL; /* To be sure. */
- a->format_data = &zip;
-
a->pad_uncompressed = 0; /* Actually not needed for now, since no compression support yet. */
a->format_write_header = archive_write_zip_header;
a->format_write_data = archive_write_zip_data;
@@ -117,8 +122,8 @@
encode(
ZIP_SIGNATURE_DATA_DESCRIPTOR,
- &zip.data_descriptor.signature,
- sizeof(zip.data_descriptor.signature)
+ &zip->data_descriptor.signature,
+ sizeof(zip->data_descriptor.signature)
);
return (ARCHIVE_OK);
@@ -134,7 +139,7 @@
struct zip *zip;
struct zip_local_file_header h;
struct zip_data_descriptor *d;
- struct zip_entry_list l;
+ struct zip_entry_list *l;
int ret;
zip = (struct zip *) a->format_data;
@@ -168,9 +173,14 @@
/* Append archive entry to the central directory data.
* Storing in reverse order, for ease of coding.
* According to specification order should not matter, right? */
- l.entry = entry;
- l.next = zip->central_directory;
- zip->central_directory = &l;
+ l = (struct zip_entry_list *) malloc(sizeof(*l));
+ if (l == NULL) {
+ archive_set_error(&a->archive, ENOMEM, "Can't allocate zip header data");
+ return (ARCHIVE_FATAL);
+ }
+ l->entry = entry;
+ l->next = zip->central_directory;
+ zip->central_directory = l;
int64_t size = archive_entry_size(entry);
encode(size, &d->compressed_size, sizeof(d->compressed_size));
@@ -229,8 +239,14 @@
archive_write_zip_destroy(struct archive_write *a)
{
struct zip *zip;
+ struct zip_entry_list *l;
zip = (struct zip *)a->format_data;
+ l = (struct zip_entry_list *) zip->central_directory;
+ while (l != NULL) {
+ l = l->next;
+ free(l);
+ }
free(zip);
a->format_data = NULL;
return (ARCHIVE_OK);
More information about the p4-projects
mailing list