Fix json buffer reallocation issue
Instead of try to guess if we will need more space for future inserions, wait for exhaustion and allocate twice the required space. This is far from perfect but works better. Now Json output works all the time.
This commit is contained in:
parent
5656777bda
commit
b6ecedbe2f
11
dump1090.c
11
dump1090.c
@ -2175,13 +2175,18 @@ char *aircraftsToJson(int *len) {
|
||||
a->reg?a->reg->code:"",
|
||||
a->flight, a->lat, a->lon, a->altitude, a->track,
|
||||
a->speed);
|
||||
p += l; buflen -= l;
|
||||
|
||||
/* Resize if needed. */
|
||||
if (buflen < 256) {
|
||||
if (l >= buflen) {
|
||||
int used = p-buf;
|
||||
buflen += 1024; /* Our increment. */
|
||||
buflen += (2*l); /* Our increment. */
|
||||
buf = realloc(buf,used+buflen);
|
||||
if (buf == NULL) exit(1);
|
||||
p = buf+used;
|
||||
/* try to add the current airplane again */
|
||||
continue;
|
||||
} else {
|
||||
p += l; buflen -= l;
|
||||
}
|
||||
}
|
||||
a = a->next;
|
||||
|
Loading…
Reference in New Issue
Block a user