Skip to content

Commit e53628a

Browse files
authored
Fix segfault in grdtrack -E<lines>+c (#8729)
* FIX: in *gmt_make_profiles* , fix annotation typos of +c and +d * FIX: in *gmt_make_profiles* , add `get_distances` check to avoid segfault when using +c
1 parent cd47fef commit e53628a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/gmt_support.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11348,8 +11348,8 @@ struct GMT_DATASET *gmt_make_profiles (struct GMT_CTRL *GMT, char option, char *
1134811348

1134911349
/* step is given in either Cartesian units or, for geographic, in the prevailing unit (m, km) */
1135011350

11351-
if (strstr (args, "+c")) continuous = true; /* Want to add distances to the output */
11352-
if (strstr (args, "+d")) get_distances = true; /* Want to join abutting profiles */
11351+
if (strstr (args, "+c")) continuous = true; /* Want to join abutting profiles */
11352+
if (strstr (args, "+d")) get_distances = true; /* Want to add distances to the output */
1135311353
if (strstr (args, "+g")) gridline_units = true; /* Want degree longitudes or latitudes along a gridline */
1135411354
if (strstr (args, "+p")) parallel = true; /* Want to sample along a parallel */
1135511355
if (strstr (args, "+x")) GMT->current.map.loxodrome = true; /* Want to sample along a rhumbline */
@@ -11543,8 +11543,10 @@ struct GMT_DATASET *gmt_make_profiles (struct GMT_CTRL *GMT, char option, char *
1154311543
else { /* Copy over but avoid repeating the joint */
1154411544
gmt_M_memcpy (&(prev_S->data[GMT_X][start]), &(S->data[GMT_X][1]), add, double);
1154511545
gmt_M_memcpy (&(prev_S->data[GMT_Y][start]), &(S->data[GMT_Y][1]), add, double);
11546-
gmt_M_memcpy (&(prev_S->data[GMT_Z][start]), &(S->data[GMT_Z][1]), add, double);
11547-
for (rec = start; rec < prev_S->n_rows; rec++) prev_S->data[GMT_Z][rec] += prev_S->data[GMT_Z][start-1];
11546+
if(get_distances){
11547+
gmt_M_memcpy (&(prev_S->data[GMT_Z][start]), &(S->data[GMT_Z][1]), add, double);
11548+
for (rec = start; rec < prev_S->n_rows; rec++) prev_S->data[GMT_Z][rec] += prev_S->data[GMT_Z][start-1];
11549+
}
1154811550
gmt_free_segment (GMT, &S); /* Done with this guy */
1154911551
S = prev_S;
1155011552
}

0 commit comments

Comments
 (0)