From 6f4df8da504c7eb6c79e629370c1174701a9c9d9 Mon Sep 17 00:00:00 2001 From: Joaquim Date: Fri, 23 Jan 2026 18:18:07 +0000 Subject: [PATCH] Let country names also have the continent code. But only for externals. Also add a test to prevent crashes when tag in -E"Looooong tag" is too long (> 30 chars) --- src/gmt_dcw.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/gmt_dcw.c b/src/gmt_dcw.c index 7abf1ebe4cc..3bc7e42c2cc 100644 --- a/src/gmt_dcw.c +++ b/src/gmt_dcw.c @@ -464,7 +464,7 @@ struct GMT_DATASET *gmt_DCW_operation(struct GMT_CTRL *GMT, struct GMT_DCW_SELEC bool done, want_state, outline, fill = false, is_Antarctica = false, hole, new_CN_codes = false; bool dtype_is_float = false, ALL = false; char TAG[GMT_LEN16] = {""}, dim[GMT_LEN16] = {""}, xname[GMT_LEN16] = {""}; - char yname[GMT_LEN16] = {""}, code[GMT_LEN16] = {""}, state[GMT_LEN16] = {""}, datatype[GMT_LEN8] = {""}; + char yname[GMT_LEN16] = {""}, code[GMT_LEN32] = {""}, state[GMT_LEN16] = {""}, datatype[GMT_LEN8] = {""}; char msg[GMT_BUFSIZ] = {""}, path[PATH_MAX] = {""}, list[GMT_BUFSIZ] = {""}, dcw_name[GMT_LEN256] = {""}; char version[GMT_LEN32] = {""}, gmtversion[GMT_LEN32] = {""}, source[GMT_LEN256] = {""}, title[GMT_LEN256] = {""}; char label[GMT_LEN256] = {""}, header[GMT_LEN256] = {""}, ISO[GMT_LEN8] = {""}; @@ -482,6 +482,10 @@ struct GMT_DATASET *gmt_DCW_operation(struct GMT_CTRL *GMT, struct GMT_DCW_SELEC for (j = ks = 0; j < F->n_items; j++) { if (!F->item[j]->codes || F->item[j]->codes[0] == '\0') continue; + if (F->item[j]->codes && strlen(F->item[j]->codes) > 30) { /* This also protects from a crash due to 'code' overflow. */ + GMT_Report(GMT->parent, GMT_MSG_ERROR, "Code \"%s\" too long (> 30). We don't have that long codes\n", F->item[j]->codes); + continue; + } ks++; /* Gave some codes */ } if (ks == 0) return NULL; /* No countries requested */ @@ -731,7 +735,7 @@ struct GMT_DATASET *gmt_DCW_operation(struct GMT_CTRL *GMT, struct GMT_DCW_SELEC else { snprintf(TAG, GMT_LEN16, "%s", GMT_DCW_country[k].code); if (F->mode & GMT_DCW_ZHEADER) - snprintf(msg, GMT_BUFSIZ, "-Z%s %s\n", TAG, GMT_DCW_country[k].name); + snprintf(msg, GMT_BUFSIZ, "-Z%s %s (%s)\n", TAG, GMT_DCW_country[k].name, GMT_DCW_country[k].continent); else snprintf(msg, GMT_BUFSIZ, "%s\n", GMT_DCW_country[k].name); } @@ -867,10 +871,13 @@ struct GMT_DATASET *gmt_DCW_operation(struct GMT_CTRL *GMT, struct GMT_DCW_SELEC P->n_rows = last - first + 1; /* Number of points in this segment */ P->data[GMT_X] = &lon[first]; P->data[GMT_Y] = &lat[first]; - sprintf(label, " %s Segment %" PRIu64, msg, seg); + if (GMT->parent->external && F->mode & GMT_DCW_ZHEADER) + sprintf(label, " %s", msg); + else + sprintf(label, " %s Segment %" PRIu64, msg, seg); header[0] = '\0'; if (hole) - strcat (header, "-Ph"); + strcat(header, "-Ph"); if (mode & GMT_DCW_DUMP) { /* Dump the coordinates to stdout */ strcat(header, label);