diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-06-27 22:03:53 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-11-09 19:19:04 +0100 |
commit | 16bdbc54b9b1966c03745ec54aa75a893ee89f16 (patch) | |
tree | 42129841a0bbd1cc856b7a6accfb70d2c6b29a66 /core/profile.c | |
parent | ff653f721c01b98587236c0b4e0cf662cb3a33a6 (diff) | |
download | subsurface-16bdbc54b9b1966c03745ec54aa75a893ee89f16.tar.gz |
Cylinders: dynamically allocate cylinder arrays
Dynamically allocate cylinder arrays in C code. This is a tiny
step in removing the MAX_CYLINDERS limitation.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/profile.c')
-rw-r--r-- | core/profile.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/core/profile.c b/core/profile.c index ff9575700..61dfa808b 100644 --- a/core/profile.c +++ b/core/profile.c @@ -828,15 +828,18 @@ static void setup_gas_sensor_pressure(const struct dive *dive, const struct dive { int prev, i; const struct event *ev; - int seen[MAX_CYLINDERS] = { 0, }; - unsigned int first[MAX_CYLINDERS] = { 0, }; - unsigned int last[MAX_CYLINDERS] = { 0, }; + int *seen = malloc(MAX_CYLINDERS * sizeof(*seen)); + int *first = malloc(MAX_CYLINDERS * sizeof(*first)); + int *last = malloc(MAX_CYLINDERS * sizeof(*last)); const struct divecomputer *secondary; + for (i = 0; i < MAX_CYLINDERS; i++) { + seen[i] = 0; + first[i] = 0; + last[i] = INT_MAX; + } prev = explicit_first_cylinder(dive, dc); seen[prev] = 1; - for (i = 0; i < MAX_CYLINDERS; i++) - last[i] = INT_MAX; for (ev = get_next_event(dc->events, "gaschange"); ev != NULL; ev = get_next_event(ev->next, "gaschange")) { int cyl = ev->gas.index; @@ -909,6 +912,10 @@ static void setup_gas_sensor_pressure(const struct dive *dive, const struct dive continue; populate_secondary_sensor_data(dc, pi); } while ((secondary = secondary->next) != NULL); + + free(seen); + free(first); + free(last); } #ifndef SUBSURFACE_MOBILE |