Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/imagery/iscatt_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,9 @@ static int compute_scatts_from_chunk_row(struct scCats *scatt_conds,
int *fd_cats_rasts)
{

int i_rows_pix, i_cat, i_scatt, n_pixs;
int i_rows_pix, i_cat, i_scatt;
int cat_id, scatt_plts_cat_idx, array_idx, max_arr_idx;
size_t n_pixs;
char *b_1_null_row, *b_2_null_row;
struct rast_row b_1_rast_row, b_2_rast_row;
CELL *cat_rast_row;
Expand Down Expand Up @@ -522,7 +523,7 @@ static int compute_scatts_from_chunk_row(struct scCats *scatt_conds,
"Unable to read from category raster condition file."));
return -1;
}
if (n_pixs != (row_size) / (int)sizeof(unsigned char)) {
if (n_pixs != ((unsigned)row_size / sizeof(unsigned char))) {
G_free(rast_pixs);
G_free(belongs_pix);
G_warning(
Expand Down Expand Up @@ -721,7 +722,7 @@ int I_compute_scatts(struct Cell_head *region, struct scCats *scatt_conds,
for (i_cat = 0; i_cat < scatts->n_a_cats; i_cat++)
fd_cats_rasts[i_cat] = -1;

G_zero(b_needed_bands, (size_t)n_bands * sizeof(int));
G_zero(b_needed_bands, n_bands * (unsigned)sizeof(int));

Comment on lines +725 to 726

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allocate the array with G_calloc() at line 713:

    int *b_needed_bands = G_calloc(n_bands, sizeof(int));

Then remove this call:

Suggested change
G_zero(b_needed_bands, n_bands * (unsigned)sizeof(int));

get_needed_bands(scatt_conds, &b_needed_bands[0]);
get_needed_bands(scatts, &b_needed_bands[0]);
Expand Down
2 changes: 1 addition & 1 deletion lib/imagery/list_gp.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int I_list_group(const char *group, const struct Ref *ref, FILE *fd)
max = 0;
for (i = 0; i < ref->nfiles; i++) {
I__list_group_name_fit(buf, ref->file[i].name, ref->file[i].mapset);
len = strlen(buf) + 4;
len = (int)strlen(buf) + 4;
if (len > max)
max = len;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/imagery/list_subgp.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ int I_list_subgroup(const char *group, const char *subgroup,
max = 0;
for (i = 0; i < ref->nfiles; i++) {
I__list_group_name_fit(buf, ref->file[i].name, ref->file[i].mapset);
len = strlen(buf) + 4;
len = (int)strlen(buf) + 4;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the result of strlen is not a size_t this time? I'm trying to understand the pattern (for my understanding)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buf is of size 80 (char buf[80]), so casting is absolutely safe here. size_t is unsigned, so for avoiding further issues like "comparison between signed and unsigned" (if I were to change len to size_t), I stay with the cast here.
So the pattern is: if I can change type without cascading issues and minimal overall changes, that is my preferred solution, otherwise I look for an alternative, locally adapted solution.

if (len > max)
max = len;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/imagery/loc_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ char *I_location_info(const char *middle)
char left[80];
char right[80];
char *buf;
int len, buf_len;
size_t len, buf_len;

snprintf(left, 80, "LOCATION: %s", G_location());
snprintf(right, 80, "MAPSET: %s", G_mapset());
len = 79 - strlen(left) - strlen(middle) - strlen(right);
buf_len = len + strlen(left) + strlen(middle) + strlen(right);
buf = (char *)G_calloc(buf_len, sizeof(char));
snprintf(buf, buf_len, "%s%*s%s%*s%s", left, len / 2, "", middle, len / 2,
"", right);
snprintf(buf, buf_len, "%s%*s%s%*s%s", left, (int)(len / 2), "", middle,
(int)(len / 2), "", right);

return buf;
}
2 changes: 1 addition & 1 deletion lib/imagery/manage_signatures.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ static int list_by_type(I_SIGFILE_TYPE type, const char *mapset, int base,
}

/* Make items fully qualified names */
int mapset_len = strlen(mapset);
size_t mapset_len = strlen(mapset);

*out_list = (char **)G_realloc(*out_list, (base + count) * sizeof(char *));
for (int i = 0; i < count; i++) {
Expand Down
3 changes: 2 additions & 1 deletion lib/imagery/sig.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ int I_write_signatures(FILE *fd, struct Signature *S)
char **I_sort_signatures_by_semantic_label(struct Signature *S,
const struct Ref *R)
{
unsigned int total, complete;
unsigned int complete;
size_t total;
unsigned int *match1, *match2, mc1, mc2, *new_order;
double **new_means, ***new_vars;
char **group_semantic_labels, **mismatches, **new_semantic_labels;
Expand Down
3 changes: 2 additions & 1 deletion lib/imagery/sigset.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,8 @@ int I_WriteSigSet(FILE *fd, const struct SigSet *S)
*/
char **I_SortSigSetBySemanticLabel(struct SigSet *S, const struct Ref *R)
{
unsigned int total, complete;
unsigned int complete;
size_t total;
unsigned int *match1, *match2, mc1, mc2, *new_order;
double ***new_means, ****new_vars;
char **group_semantic_labels, **mismatches, **new_semantic_labels;
Expand Down
Loading