csiro-coasts / EMS

Environmental Modelling Suite
Other
15 stars 5 forks source link

`sal` and `temp` not initialized before use #17

Closed rountree closed 10 months ago

rountree commented 4 years ago

In file model/hd/outputs/timeseries.c (1546) and model/hd-us/outputs/timeseries.c (1605) both sal and temp are not initialized before first use. They are both initialized later on in the function.

1546 int read_ts_data(master_t *master, ts_point_t *tslist, double t, int c)
...
1552   double temp, sal, p, dens;
...
1604             /* Compute glider density if not supplied in the file    */
1605             if (densf) {
1606               p = master->glider[c] * 1e6;
1607               /* eos2 expects pressure as N/m2 and converts to bars  */
1608               /* (divides by 1e5), so multiply p by 1e6 to retrieve  */
1609               /* bars in eos2().                                     */
1610               eos2(sal, temp, p, &dens, &master->glider[c]);
1611             }
...
1640             if (densf) {
1641               p = master->glider[zm1] * 1e6;
1642               temp = average_glider_data(master, tslist, tzm1, zm1, tid, &cud, &cdd, &d1, &d2, &nvals);
1643               sal = average_glider_data(master, tslist, tzm1, zm1, sid, &cud, &cdd, &d1, &d2, &nvals);
1644               eos2(sal, temp, p, &dens, &master->glider[zm1]);
1645             }

I'll provide a PR that copies the initial code into the first stanza. Needs reviewed to make sure that's a valid initialization.

Update: sid and tid are also uninitialized before first use in lines 1642-3 (their initialization starts on line 1652). That invalidates my proposed fix.

frizwi commented 10 months ago

Fixed in latest