Skip to content
Draft
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
22 changes: 21 additions & 1 deletion raster/r.clump/clump.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@
#include <grass/glocale.h>
#include "local_proto.h"
#include <errno.h>
#include <limits.h>
#include <string.h>

#define INCR 1024
#define INCR 1024

/* Clump IDs are stored as CELL, a 32 bit signed integer, so the number of
* clumps cannot exceed the largest CELL value. Stopping INCR short of that
* also keeps nalloc, which grows in INCR steps, from overflowing. */
#define MAX_LABEL (INT_MAX - INCR)

int print_time(time_t *);

Expand Down Expand Up @@ -311,6 +317,13 @@ CELL clump(int *in_fd, int out_fd, int diag, int minsize)
if (NEW == 0 || OLD == NEW) { /* ok */
if (OLD == 0) {
/* start a new clump */
if (label >= MAX_LABEL)
G_fatal_error(
_("Too many clumps: the maximum supported number "
"of clumps is %d. Reduce the extent or the "
"resolution of the computational region, or use "
"a threshold to merge similar cells."),
MAX_LABEL);
label++;
cur_clump[col] = label;
if (label >= nalloc) {
Expand Down Expand Up @@ -641,6 +654,13 @@ CELL clump_n(int *in_fd, char **inname, int nin, double threshold, int out_fd,
if (NEW == 0 || OLD == NEW) { /* ok */
if (OLD == 0) {
/* start a new clump */
if (label >= MAX_LABEL)
G_fatal_error(
_("Too many clumps: the maximum supported number "
"of clumps is %d. Reduce the extent or the "
"resolution of the computational region, or use "
"a threshold to merge similar cells."),
MAX_LABEL);
label++;
cur_clump[col] = label;
if (label >= nalloc) {
Expand Down
Loading