Skip to content

Commit

Permalink
Fixed checks of array dimensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
lars2015 committed Jul 26, 2024
1 parent 3632423 commit 1e953e2
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/atm_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ int main(
}

/* Set particle counter... */
if ((++atm->np) > NP)
if ((++atm->np) >= NP)
ERRMSG("Too many particles!");
}

Expand Down
2 changes: 1 addition & 1 deletion src/atm_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ int main(
atm2->lat[atm2->np] = atm->lat[ip];
for (int iq = 0; iq < ctl.nq; iq++)
atm2->q[iq][atm2->np] = atm->q[iq][ip];
if ((++atm2->np) > NP)
if ((++atm2->np) >= NP)
ERRMSG("Too many air parcels!");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/atm_split.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ int main(
atm2->q[ctl.qnt_idx][atm2->np] = atm2->np;

/* Increment particle counter... */
if ((++atm2->np) > NP)
if ((++atm2->np) >= NP)
ERRMSG("Too many air parcels!");
}

Expand Down
4 changes: 2 additions & 2 deletions src/met_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ int main(
nx = ny = 0;
for (lon = lon0; lon <= lon1; lon += dlon) {
lons[nx] = lon;
if ((++nx) > NX)
if ((++nx) >= NX)
ERRMSG("Too many longitudes!");
}
if (lat0 < -90 && lat1 > 90) {
Expand All @@ -209,7 +209,7 @@ int main(
}
for (lat = lat0; lat <= lat1; lat += dlat) {
lats[ny] = lat;
if ((++ny) > NY)
if ((++ny) >= NY)
ERRMSG("Too many latitudes!");
}

Expand Down
4 changes: 2 additions & 2 deletions src/met_prof.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ int main(
for (iz = 0; iz < met->np; iz++)
if (Z(met->p[iz]) >= z0 && Z(met->p[iz]) <= z1) {
plev[nz] = met->p[iz];
if ((++nz) > NZ)
if ((++nz) >= NZ)
ERRMSG("Too many pressure levels!");
}
} else
for (z = z0; z <= z1; z += dz) {
plev[nz] = P(z);
if ((++nz) > NZ)
if ((++nz) >= NZ)
ERRMSG("Too many pressure levels!");
}

Expand Down
6 changes: 3 additions & 3 deletions src/met_zm.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ int main(
for (int iz = 0; iz < met->np; iz++)
if (Z(met->p[iz]) >= z0 && Z(met->p[iz]) <= z1) {
plev[nz] = met->p[iz];
if ((++nz) > NZ)
if ((++nz) >= NZ)
ERRMSG("Too many pressure levels!");
}
} else
for (z = z0; z <= z1; z += dz) {
plev[nz] = P(z);
if ((++nz) > NZ)
if ((++nz) >= NZ)
ERRMSG("Too many pressure levels!");
}

Expand All @@ -124,7 +124,7 @@ int main(
}
for (lat = lat0; lat <= lat1; lat += dlat) {
lats[ny] = lat;
if ((++ny) > NY)
if ((++ny) >= NY)
ERRMSG("Too many latitudes!");
}

Expand Down
14 changes: 7 additions & 7 deletions src/mptrac.c
Original file line number Diff line number Diff line change
Expand Up @@ -3033,7 +3033,7 @@ void module_isosurf_init(
while (fgets(line, LEN, in))
if (sscanf(line, "%lg %lg", &(cache->iso_ts[cache->iso_n]),
&(cache->iso_ps[cache->iso_n])) == 2)
if ((++cache->iso_n) > NP)
if ((++cache->iso_n) >= NP)
ERRMSG("Too many data points!");

/* Check number of points... */
Expand Down Expand Up @@ -4239,7 +4239,7 @@ int read_atm_asc(
atm->p[atm->np] = P(atm->p[atm->np]);

/* Increment data point counter... */
if ((++atm->np) > NP)
if ((++atm->np) >= NP)
ERRMSG("Too many data points!");
}

Expand Down Expand Up @@ -4620,7 +4620,7 @@ int read_clim_ts(
ERRMSG("Time series must be ascending!");

/* Count time steps... */
if ((++nh) >= 1000)
if ((++nh) >= CTS)
ERRMSG("Too many data points!");
}

Expand Down Expand Up @@ -7121,7 +7121,7 @@ void read_met_periodic(
return;

/* Increase longitude counter... */
if ((++met->nx) > EX)
if ((++met->nx) >= EX)
ERRMSG("Cannot create periodic boundary conditions!");

/* Set longitude... */
Expand Down Expand Up @@ -8195,14 +8195,14 @@ void timer(
/* Check whether this is a new timer... */
if (iname >= nname) {
sprintf(names[iname], "%s", name);
if ((++nname) > NTIMER)
if ((++nname) >= NTIMER)
ERRMSG("Too many timers!");
}

/* Check whether this is a new group... */
if (igroup >= ngroup) {
sprintf(groups[igroup], "%s", group);
if ((++ngroup) > NTIMER)
if ((++ngroup) >= NTIMER)
ERRMSG("Too many groups!");
}

Expand Down Expand Up @@ -8897,7 +8897,7 @@ void write_csi(
y[n] = obsmean[idx];
if (modmean[idx] >= ctl->csi_modmin)
obsstdn[n] = obsstd[idx];
if ((++n) > NCSI)
if ((++n) >= NCSI)
ERRMSG("Too many data points to calculate statistics!");
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/tropo.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ int main(
nx = ny = 0;
for (lon = lon0; lon <= lon1; lon += dlon) {
lons[nx] = lon;
if ((++nx) > EX)
if ((++nx) >= EX)
ERRMSG("Too many longitudes!");
}
if (lat0 < -90 && lat1 > 90) {
Expand All @@ -98,7 +98,7 @@ int main(
}
for (lat = lat0; lat <= lat1; lat += dlat) {
lats[ny] = lat;
if ((++ny) > EY)
if ((++ny) >= EY)
ERRMSG("Too many latitudes!");
}

Expand Down

0 comments on commit 1e953e2

Please sign in to comment.