aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contrib/minizip/skipset.h22
-rw-r--r--contrib/minizip/zip.c19
2 files changed, 26 insertions, 15 deletions
diff --git a/contrib/minizip/skipset.h b/contrib/minizip/skipset.h
index ec4d4ab4..3878bcfe 100644
--- a/contrib/minizip/skipset.h
+++ b/contrib/minizip/skipset.h
@@ -91,10 +91,12 @@ void set_uniq(set_rand_t *gen, const void *ptr) {
91} 91}
92/* Return 32 random bits, advancing the state *gen. */ 92/* Return 32 random bits, advancing the state *gen. */
93ui32_t set_rand(set_rand_t *gen) { 93ui32_t set_rand(set_rand_t *gen) {
94 ui32_t mix;
95 int rot;
94 ui64_t state = gen->state; 96 ui64_t state = gen->state;
95 gen->state = state * 6364136223846793005ULL + gen->inc; 97 gen->state = state * 6364136223846793005ULL + gen->inc;
96 ui32_t mix = (ui32_t)(((state >> 18) ^ state) >> 27); 98 mix = (ui32_t)(((state >> 18) ^ state) >> 27);
97 int rot = state >> 59; 99 rot = state >> 59;
98 return (mix >> rot) | (mix << ((-rot) & 31)); 100 return (mix >> rot) | (mix << ((-rot) & 31));
99} 101}
100/* End of PCG32 code. */ 102/* End of PCG32 code. */
@@ -185,6 +187,7 @@ void set_free(set_t *set, void *ptr) {
185// setting them to set->head if not previously filled in. Otherwise it is 187// setting them to set->head if not previously filled in. Otherwise it is
186// assumed that the first want links are about to be filled in. */ 188// assumed that the first want links are about to be filled in. */
187void set_grow(set_t *set, set_node_t *node, int want, int fill) { 189void set_grow(set_t *set, set_node_t *node, int want, int fill) {
190 int i;
188 if (node->size < want) { 191 if (node->size < want) {
189 int more = node->size ? node->size : 1; 192 int more = node->size ? node->size : 1;
190 while (more < want) 193 while (more < want)
@@ -193,7 +196,6 @@ void set_grow(set_t *set, set_node_t *node, int want, int fill) {
193 (size_t)more * sizeof(set_node_t *)); 196 (size_t)more * sizeof(set_node_t *));
194 node->size = (i16_t)more; 197 node->size = (i16_t)more;
195 } 198 }
196 int i;
197 if (fill) 199 if (fill)
198 for (i = node->fill; i < want; i++) 200 for (i = node->fill; i < want; i++)
199 node->right[i] = set->head; 201 node->right[i] = set->head;
@@ -298,11 +300,14 @@ void set_end(set_t *set) {
298/* Look for key. Return 1 if found or 0 if not. This also puts the path to get 300/* Look for key. Return 1 if found or 0 if not. This also puts the path to get
299// there in set->path, for use by set_insert(). */ 301// there in set->path, for use by set_insert(). */
300int set_found(set_t *set, set_key_t key) { 302int set_found(set_t *set, set_key_t key) {
303 set_node_t *head, *here;
304 int i;
301 assert(set_ok(set) && "improper use"); 305 assert(set_ok(set) && "improper use");
302 306
303 /* Start at depth and work down and right as determined by key comparisons. */ 307 /* Start at depth and work down and right as determined by key comparisons. */
304 set_node_t *head = set->head, *here = head; 308 head = set->head;
305 int i = set->depth; 309 here = head;
310 i = set->depth;
306 set_grow(set, set->path, i + 1, 0); 311 set_grow(set, set->path, i + 1, 0);
307 do { 312 do {
308 while (here->right[i] != head && 313 while (here->right[i] != head &&
@@ -318,6 +323,9 @@ int set_found(set_t *set, set_key_t key) {
318 323
319/* Insert the key key. Return 0 on success, or 1 if key is already in the set. */ 324/* Insert the key key. Return 0 on success, or 1 if key is already in the set. */
320int set_insert(set_t *set, set_key_t key) { 325int set_insert(set_t *set, set_key_t key) {
326 int level = 0;
327 int bit;
328 int i;
321 assert(set_ok(set) && "improper use"); 329 assert(set_ok(set) && "improper use");
322 330
323 if (set_found(set, key)) 331 if (set_found(set, key))
@@ -326,12 +334,11 @@ int set_insert(set_t *set, set_key_t key) {
326 334
327 /* Randomly generate a new level-- level 0 with probability 1/2, 1 with 335 /* Randomly generate a new level-- level 0 with probability 1/2, 1 with
328 // probability 1/4, 2 with probability 1/8, etc. */ 336 // probability 1/4, 2 with probability 1/8, etc. */
329 int level = 0;
330 for (;;) { 337 for (;;) {
331 if (set->ran == 1) 338 if (set->ran == 1)
332 /* Ran out. Get another 32 random bits. */ 339 /* Ran out. Get another 32 random bits. */
333 set->ran = set_rand(&set->gen) | (1ULL << 32); 340 set->ran = set_rand(&set->gen) | (1ULL << 32);
334 int bit = set->ran & 1; 341 bit = set->ran & 1;
335 set->ran >>= 1; 342 set->ran >>= 1;
336 if (bit) 343 if (bit)
337 break; 344 break;
@@ -351,7 +358,6 @@ int set_insert(set_t *set, set_key_t key) {
351 set->node = set_node(set); 358 set->node = set_node(set);
352 set->node->key = key; 359 set->node->key = key;
353 set_grow(set, set->node, level + 1, 0); 360 set_grow(set, set->node, level + 1, 0);
354 int i;
355 for (i = 0; i <= level; i++) { 361 for (i = 0; i <= level; i++) {
356 set->node->right[i] = set->path->right[i]->right[i]; 362 set->node->right[i] = set->path->right[i]->right[i];
357 set->path->right[i]->right[i] = set->node; 363 set->path->right[i]->right[i] = set->node;
diff --git a/contrib/minizip/zip.c b/contrib/minizip/zip.c
index 31005c51..136c0486 100644
--- a/contrib/minizip/zip.c
+++ b/contrib/minizip/zip.c
@@ -367,6 +367,7 @@ local long block_get2(block_t *block) {
367/* Read up to len bytes from block into buf. Return the number of bytes read. */ 367/* Read up to len bytes from block into buf. Return the number of bytes read. */
368local size_t block_read(block_t *block, unsigned char *buf, size_t len) { 368local size_t block_read(block_t *block, unsigned char *buf, size_t len) {
369 size_t need = len; 369 size_t need = len;
370 size_t take;
370 while (need) { 371 while (need) {
371 if (block->left == 0) { 372 if (block->left == 0) {
372 /* Get a byte to update and step through the linked list as needed. */ 373 /* Get a byte to update and step through the linked list as needed. */
@@ -378,7 +379,7 @@ local size_t block_read(block_t *block, unsigned char *buf, size_t len) {
378 need--; 379 need--;
379 continue; 380 continue;
380 } 381 }
381 size_t take = need > block->left ? block->left : need; 382 take = need > block->left ? block->left : need;
382 memcpy(buf, block->next, take); 383 memcpy(buf, block->next, take);
383 block->next += take; 384 block->next += take;
384 block->left -= take; 385 block->left -= take;
@@ -408,6 +409,7 @@ local int block_skip(block_t *block, size_t n) {
408// zero-terminated file name, or NULL for end of input or invalid data. If 409// zero-terminated file name, or NULL for end of input or invalid data. If
409// invalid, *block is marked bad. This uses *set for the allocation of memory. */ 410// invalid, *block is marked bad. This uses *set for the allocation of memory. */
410local char *block_central_name(block_t *block, set_t *set) { 411local char *block_central_name(block_t *block, set_t *set) {
412 unsigned flen, xlen, clen;
411 char *name = NULL; 413 char *name = NULL;
412 for (;;) { 414 for (;;) {
413 if (block_end(block)) 415 if (block_end(block))
@@ -423,9 +425,9 @@ local char *block_central_name(block_t *block, set_t *set) {
423 /* Go through the remaining fixed-length portion of the record, 425 /* Go through the remaining fixed-length portion of the record,
424 // extracting the lengths of the three variable-length fields. */ 426 // extracting the lengths of the three variable-length fields. */
425 block_skip(block, 24); 427 block_skip(block, 24);
426 unsigned flen = (unsigned)block_get2(block); /* file name length */ 428 flen = (unsigned)block_get2(block); /* file name length */
427 unsigned xlen = (unsigned)block_get2(block); /* extra length */ 429 xlen = (unsigned)block_get2(block); /* extra length */
428 unsigned clen = (unsigned)block_get2(block); /* comment length */ 430 clen = (unsigned)block_get2(block); /* comment length */
429 if (block_skip(block, 12) == -1) 431 if (block_skip(block, 12) == -1)
430 /* Premature end of the record. */ 432 /* Premature end of the record. */
431 break; 433 break;
@@ -463,6 +465,9 @@ local char *block_central_name(block_t *block, set_t *set) {
463// the central directory is invalid, -2 if out of memory, or ZIP_PARAMERROR if 465// the central directory is invalid, -2 if out of memory, or ZIP_PARAMERROR if
464// file is NULL. */ 466// file is NULL. */
465extern int ZEXPORT zipAlreadyThere(zipFile file, char const *name) { 467extern int ZEXPORT zipAlreadyThere(zipFile file, char const *name) {
468 size_t len;
469 char *copy;
470 int found;
466 zip64_internal *zip = file; 471 zip64_internal *zip = file;
467 if (zip == NULL) 472 if (zip == NULL)
468 return ZIP_PARAMERROR; 473 return ZIP_PARAMERROR;
@@ -501,10 +506,10 @@ extern int ZEXPORT zipAlreadyThere(zipFile file, char const *name) {
501 } 506 }
502 507
503 /* Return true if name is in the central directory. */ 508 /* Return true if name is in the central directory. */
504 size_t len = strlen(name); 509 len = strlen(name);
505 char *copy = set_alloc(&zip->set, NULL, len + 1); 510 copy = set_alloc(&zip->set, NULL, len + 1);
506 memcpy(copy, name, len + 1); 511 memcpy(copy, name, len + 1);
507 int found = set_found(&zip->set, copy); 512 found = set_found(&zip->set, copy);
508 set_free(&zip->set, copy); 513 set_free(&zip->set, copy);
509 return found; 514 return found;
510} 515}