Move variable definitions to the start of their respective blocks.
Improves support for older compilers.
From Boaz Stolk <bstolk@aweta.nl>.
diff --git a/lib/zip_dirent.c b/lib/zip_dirent.c
index cac1565..de6ade8 100644
--- a/lib/zip_dirent.c
+++ b/lib/zip_dirent.c
@@ -613,6 +613,8 @@
zip_uint16_t dostime, dosdate;
zip_encoding_type_t com_enc, name_enc;
zip_extra_field_t *ef;
+ zip_extra_field_t *ef64;
+ zip_uint32_t ef_total_size;
bool is_zip64;
bool is_really_zip64;
zip_uint8_t buf[CDENTRYSIZE];
@@ -686,7 +688,7 @@
return -1;
}
- zip_extra_field_t *ef64 = _zip_ef_new(ZIP_EF_ZIP64, (zip_uint16_t)(_zip_buffer_offset(ef_buffer)), ef_zip64, ZIP_EF_BOTH);
+ ef64 = _zip_ef_new(ZIP_EF_ZIP64, (zip_uint16_t)(_zip_buffer_offset(ef_buffer)), ef_zip64, ZIP_EF_BOTH);
_zip_buffer_free(ef_buffer);
ef64->next = ef;
ef = ef64;
@@ -739,7 +741,7 @@
_zip_buffer_put_16(buffer, _zip_string_length(de->filename));
/* TODO: check for overflow */
- zip_uint32_t ef_total_size = (zip_uint32_t)_zip_ef_size(de->extra_fields, flags) + (zip_uint32_t)_zip_ef_size(ef, ZIP_EF_BOTH);
+ ef_total_size = (zip_uint32_t)_zip_ef_size(de->extra_fields, flags) + (zip_uint32_t)_zip_ef_size(ef, ZIP_EF_BOTH);
_zip_buffer_put_16(buffer, (zip_uint16_t)ef_total_size);
if ((flags & ZIP_FL_LOCAL) == 0) {
diff --git a/lib/zip_source_buffer.c b/lib/zip_source_buffer.c
index e2c5b5a..ea502c9 100644
--- a/lib/zip_source_buffer.c
+++ b/lib/zip_source_buffer.c
@@ -375,6 +375,7 @@
buffer_write(buffer_t *buffer, const zip_uint8_t *data, zip_uint64_t length, zip_error_t *error)
{
zip_uint64_t n, i, fragment_offset;
+ zip_uint8_t **fragments;
if (buffer->offset + length + buffer->fragment_size - 1 < length) {
zip_error_set(error, ZIP_ER_INVAL, 0);
@@ -392,7 +393,7 @@
new_capacity *= 2;
}
- zip_uint8_t **fragments = realloc(buffer->fragments, new_capacity * sizeof(*fragments));
+ fragments = realloc(buffer->fragments, new_capacity * sizeof(*fragments));
if (fragments == NULL) {
zip_error_set(error, ZIP_ER_MEMORY, 0);
diff --git a/lib/zip_source_win32handle.c b/lib/zip_source_win32handle.c
index 7e30dfc..20b2521 100644
--- a/lib/zip_source_win32handle.c
+++ b/lib/zip_source_win32handle.c
@@ -408,6 +408,7 @@
static int
_win32_create_temp_file(_zip_source_win32_read_file_t *ctx)
{
+ zip_uint32_t value;
/*
Windows has GetTempFileName(), but it closes the file after
creation, leaving it open to a horrible race condition. So
@@ -447,7 +448,7 @@
}
}
- zip_uint32_t value = GetTickCount();
+ value = GetTickCount();
for (i = 0; i < 1024 && th == INVALID_HANDLE_VALUE; i++) {
th = ctx->ops->op_create_temp(ctx, &temp, value + i, psa);
if (th == INVALID_HANDLE_VALUE && GetLastError() != ERROR_FILE_EXISTS)