mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-05 18:05:42 +02:00
Fix numeric overflow
This commit is contained in:
@@ -1,18 +1,18 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <limits.h>
|
||||||
#include "memfile.hpp"
|
#include "memfile.hpp"
|
||||||
#include "pool.hpp"
|
#include "pool.hpp"
|
||||||
|
|
||||||
#define POOL_WIDTH 256
|
#define POOL_WIDTH 256
|
||||||
|
|
||||||
static int hash(const char *s) {
|
static int hash(const char *s) {
|
||||||
int h = 0;
|
unsigned h = 0;
|
||||||
for (; *s; s++) {
|
for (; *s; s++) {
|
||||||
h = h * 37 + *s;
|
h = (h * 37 + *s) & ULONG_MAX;
|
||||||
}
|
}
|
||||||
h = h & 0xFF;
|
return h & 0xFF;
|
||||||
return h;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct pool_val *pool(struct pool *p, const char *s, int type) {
|
struct pool_val *pool(struct pool *p, const char *s, int type) {
|
||||||
|
|||||||
@@ -501,14 +501,14 @@ int manage_gap(unsigned long long index, unsigned long long *previndex, double s
|
|||||||
return 1; // Exact duplicate: can't fulfil the gap requirement
|
return 1; // Exact duplicate: can't fulfil the gap requirement
|
||||||
}
|
}
|
||||||
|
|
||||||
if (std::exp(std::log((index - *previndex) / scale) * gamma) >= *gap) {
|
if (index < *previndex || std::exp(std::log((index - *previndex) / scale) * gamma) >= *gap) {
|
||||||
// Dot is further from the previous than the nth root of the gap,
|
// Dot is further from the previous than the nth root of the gap,
|
||||||
// so produce it, and choose a new gap at the next point.
|
// so produce it, and choose a new gap at the next point.
|
||||||
*gap = 0;
|
*gap = 0;
|
||||||
} else {
|
} else {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (index >= *previndex) {
|
||||||
*gap = (index - *previndex) / scale;
|
*gap = (index - *previndex) / scale;
|
||||||
|
|
||||||
if (*gap == 0) {
|
if (*gap == 0) {
|
||||||
@@ -1182,8 +1182,17 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpo
|
|||||||
if (threads > useful_threads) {
|
if (threads > useful_threads) {
|
||||||
threads = useful_threads;
|
threads = useful_threads;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Round down to a power of 2
|
// Round down to a power of 2
|
||||||
threads = 1 << (int) (std::log(threads) / std::log(2));
|
for (int e = 0; e < 30; e++) {
|
||||||
|
if (threads >= (1 << e) && threads < (1 << (e + 1))) {
|
||||||
|
threads = 1 << e;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (threads >= (1 << 30)) {
|
||||||
|
threads = 1 << 30;
|
||||||
|
}
|
||||||
|
|
||||||
// Assign temporary files to threads
|
// Assign temporary files to threads
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user