Skip to content

Commit

Permalink
fix vla
Browse files Browse the repository at this point in the history
  • Loading branch information
nilason committed Dec 20, 2023
1 parent e8f5323 commit f400a98
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 28 deletions.
8 changes: 7 additions & 1 deletion imagery/i.landsat.acca/algorithm.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,12 @@ extern int hist_n;
void acca_algorithm(Gfile *out, Gfile band[], int single_pass, int with_shadow,
int cloud_signature)
{
int i, count[5], hist_cold[hist_n], hist_warm[hist_n];
int i, count[5];
double max, value[5], signa[5], idesert, review_warm, shift;

int *hist_cold = G_malloc(hist_n * sizeof(int));
int *hist_warm = G_malloc(hist_n * sizeof(int));

/* Reset variables ... */
for (i = 0; i < 5; i++) {
count[i] = 0;
Expand Down Expand Up @@ -213,6 +216,9 @@ void acca_algorithm(Gfile *out, Gfile band[], int single_pass, int with_shadow,
acca_second(out, band[BAND6], review_warm, value[KUPPER], value[KLOWER]);
/* CATEGORIES: IS_WARM_CLOUD, IS_COLD_CLOUD, IS_SHADOW, NULL (= NO_CLOUD) */

G_free(hist_cold);
G_free(hist_warm);

return;
}

Expand Down
17 changes: 9 additions & 8 deletions lib/gis/strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,17 +267,16 @@ char *G_str_replace(const char *buffer, const char *old_str,
char *G_str_concat(const char **src_strings, int num_strings, const char *sep,
int maxsize)
{
char buffer[maxsize];
int i;
char *end = buffer + maxsize;
char *p = NULL;

if (maxsize < 1 || num_strings < 1)
return NULL;

memset(buffer, 0, sizeof(buffer));
char *concat_str = NULL;
char *p = NULL;
char *buffer = G_malloc(maxsize * sizeof(char));
char *end = buffer + maxsize;

for (i = 0; i < num_strings; i++) {
memset(buffer, 0, maxsize);
for (unsigned int i = 0; i < num_strings; i++) {
if (i == 0)
p = (char *)G__memccpy(buffer, src_strings[i], '\0', maxsize);
else {
Expand All @@ -287,8 +286,10 @@ char *G_str_concat(const char **src_strings, int num_strings, const char *sep,
p = (char *)G__memccpy(p - 1, src_strings[i], '\0', end - p);
}
}
concat_str = G_store(buffer);
G_free(buffer);

return G_store(buffer);
return concat_str;
}

/*!
Expand Down
49 changes: 33 additions & 16 deletions lib/imagery/iscatt_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ static void get_needed_bands(struct scCats *cats, int *b_needed_bands)
*/
static void free_compute_scatts_data(int *fd_bands, struct rast_row *bands_rows,
int n_a_bands, int *bands_ids,
int *fd_cats_rasts,
int *fd_cats_rasts, int *b_needed_bands,
FILE **f_cats_rasts_conds, int n_a_cats)
{
int i, band_id;
Expand All @@ -641,16 +641,31 @@ static void free_compute_scatts_data(int *fd_bands, struct rast_row *bands_rows,
G_free(bands_rows[band_id].null_row);
}
}
if (bands_rows)
G_free(bands_rows);

if (f_cats_rasts_conds)
if (fd_bands)
G_free(fd_bands);

if (bands_ids)
G_free(bands_ids);

if (b_needed_bands)
G_free(b_needed_bands);

if (f_cats_rasts_conds) {
for (i = 0; i < n_a_cats; i++)
if (f_cats_rasts_conds[i])
fclose(f_cats_rasts_conds[i]);
G_free(f_cats_rasts_conds);
}

if (fd_cats_rasts)
if (fd_cats_rasts) {
for (i = 0; i < n_a_cats; i++)
if (fd_cats_rasts[i] >= 0)
Rast_close(fd_cats_rasts[i]);
G_free(fd_cats_rasts);
}
}

/*!
Expand Down Expand Up @@ -687,19 +702,21 @@ int I_compute_scatts(struct Cell_head *region, struct scCats *scatt_conds,
const char *mapset;
char header[1024];

int fd_cats_rasts[scatt_conds->n_a_cats];
FILE *f_cats_rasts_conds[scatt_conds->n_a_cats];
int *fd_cats_rasts =
G_malloc(scatt_conds->n_a_cats * sizeof(scatt_conds->n_a_cats));
FILE **f_cats_rasts_conds =
G_malloc(scatt_conds->n_a_cats * sizeof(FILE *));

struct rast_row bands_rows[n_bands];
struct rast_row *bands_rows = G_malloc(n_bands * sizeof(struct rast_row));

RASTER_MAP_TYPE data_type;

int nrows, i_band, n_a_bands, band_id;
int i_row, head_nchars, i_cat, id_cat;

int fd_bands[n_bands];
int bands_ids[n_bands];
int b_needed_bands[n_bands];
int *fd_bands = G_malloc(n_bands * sizeof(n_bands));
int *bands_ids = G_malloc(n_bands * sizeof(n_bands));
int *b_needed_bands = G_malloc(n_bands * sizeof(n_bands));

Rast_set_window(region);

Expand Down Expand Up @@ -727,7 +744,7 @@ int I_compute_scatts(struct Cell_head *region, struct scCats *scatt_conds,

if ((mapset = G_find_raster2(bands[band_id], "")) == NULL) {
free_compute_scatts_data(fd_bands, bands_rows, n_a_bands,
bands_ids, NULL, NULL,
bands_ids, NULL, b_needed_bands, NULL,
scatt_conds->n_a_cats);
G_warning(_("Unable to find raster <%s>"), bands[band_id]);
return -1;
Expand All @@ -736,7 +753,7 @@ int I_compute_scatts(struct Cell_head *region, struct scCats *scatt_conds,
if ((fd_bands[n_a_bands] = Rast_open_old(bands[band_id], mapset)) <
0) {
free_compute_scatts_data(fd_bands, bands_rows, n_a_bands,
bands_ids, NULL, NULL,
bands_ids, NULL, b_needed_bands, NULL,
scatt_conds->n_a_cats);
G_warning(_("Unable to open raster <%s>"), bands[band_id]);
return -1;
Expand All @@ -755,7 +772,7 @@ int I_compute_scatts(struct Cell_head *region, struct scCats *scatt_conds,
if (Rast_read_range(bands[band_id], mapset,
&bands_rows[band_id].rast_range) != 1) {
free_compute_scatts_data(fd_bands, bands_rows, n_a_bands,
bands_ids, NULL, NULL,
bands_ids, NULL, b_needed_bands, NULL,
scatt_conds->n_a_cats);
G_warning(_("Unable to read range of raster <%s>"),
bands[band_id]);
Expand All @@ -781,7 +798,7 @@ int I_compute_scatts(struct Cell_head *region, struct scCats *scatt_conds,
if (!f_cats_rasts_conds[i_cat]) {
free_compute_scatts_data(
fd_bands, bands_rows, n_a_bands, bands_ids, fd_cats_rasts,
f_cats_rasts_conds, scatt_conds->n_a_cats);
b_needed_bands, f_cats_rasts_conds, scatt_conds->n_a_cats);
G_warning(
_("Unable to open category raster condition file <%s>"),
bands[band_id]);
Expand Down Expand Up @@ -815,13 +832,13 @@ int I_compute_scatts(struct Cell_head *region, struct scCats *scatt_conds,
bands_rows, scatts,
fd_cats_rasts) == -1) {
free_compute_scatts_data(fd_bands, bands_rows, n_a_bands, bands_ids,
fd_cats_rasts, f_cats_rasts_conds,
scatt_conds->n_a_cats);
fd_cats_rasts, b_needed_bands,
f_cats_rasts_conds, scatt_conds->n_a_cats);
return -1;
}
}
free_compute_scatts_data(fd_bands, bands_rows, n_a_bands, bands_ids,
fd_cats_rasts, f_cats_rasts_conds,
fd_cats_rasts, b_needed_bands, f_cats_rasts_conds,
scatt_conds->n_a_cats);
return 0;
}
Expand Down
8 changes: 6 additions & 2 deletions raster/r.fill.stats/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ void print_weights_matrix(long int rows, long int cols)
{
int i, j;
size_t weight_matrix_line_length = 80;
char weight_matrix_line_buf[weight_matrix_line_length + 1];
char weight_matrix_weight_buf[weight_matrix_line_length + 1];
char *weight_matrix_line_buf =
G_malloc((weight_matrix_line_length + 1) * sizeof(char));
char *weight_matrix_weight_buf =
G_malloc((weight_matrix_line_length + 1) * sizeof(char));

G_message(_("Spatial weights neighborhood (cells):"));
for (i = 0; i < rows; i++) {
Expand All @@ -184,6 +186,8 @@ void print_weights_matrix(long int rows, long int cols)
}
fprintf(stdout, "%s\n", weight_matrix_line_buf);
}
G_free(weight_matrix_line_buf);
G_free(weight_matrix_weight_buf);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion raster/r.mapcalc/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -725,9 +725,9 @@ void copy_history(const char *dst, int idx)
Rast_write_history((char *)dst, &hist);
}

#define RECORD_LEN 80
void create_history(const char *dst, expression *e)
{
int RECORD_LEN = 80;
int WIDTH = RECORD_LEN - 12;
struct History hist;
char *expr = format_expression(e);
Expand Down

0 comments on commit f400a98

Please sign in to comment.