diff --git a/src/exch.c b/src/exch.c index 19ff2d0..caf814d 100644 --- a/src/exch.c +++ b/src/exch.c @@ -412,7 +412,7 @@ void visit_bank (void) mkchstr(chbuf, BUFSIZE, attr_normal, attr_normal | A_BOLD, 0, 1, getmaxx(curwin) / 2, &width_cursym, 1, "^{%s^}", lconvinfo.currency_symbol); - chbuf_cursym = chstrdup(chbuf); + chbuf_cursym = xchstrdup(chbuf); mkchstr(chbuf, BUFSIZE, attr_normal, 0, 0, 1, getmaxx(curwin) - BANK_INPUT_COLS - width_cursym - 6, &width, 1, @@ -470,7 +470,7 @@ void visit_bank (void) mkchstr(chbuf, BUFSIZE, attr_normal, attr_normal | A_BOLD, 0, 1, getmaxx(curwin) / 2, &width_cursym, 1, "^{%s^}", lconvinfo.currency_symbol); - chbuf_cursym = chstrdup(chbuf); + chbuf_cursym = xchstrdup(chbuf); mkchstr(chbuf, BUFSIZE, attr_normal, 0, 0, 1, getmaxx(curwin) - BANK_INPUT_COLS - width_cursym - 6, &width, 1, diff --git a/src/intf.c b/src/intf.c index 46cc3e8..cab54de 100644 --- a/src/intf.c +++ b/src/intf.c @@ -1391,28 +1391,6 @@ error: } -/***********************************************************************/ -// chstrdup: Duplicate a chtype buffer - -chtype *chstrdup (const chtype *restrict chstr) -{ - const chtype *p; - int len; - chtype *ret; - - - // Determine chstr length, including ending NUL - for (len = 1, p = chstr; *p != '\0'; p++, len++) - ; - - ret = xmalloc(len * sizeof(chtype)); - memcpy(ret, chstr, len * sizeof(chtype)); - ret[len - 1] = '\0'; // Terminating NUL, just in case not present - - return ret; -} - - /***********************************************************************/ // leftch: Print strings in chstr left-aligned diff --git a/src/intf.h b/src/intf.h index 9fcb017..8a27e0c 100644 --- a/src/intf.h +++ b/src/intf.h @@ -408,19 +408,6 @@ extern int vmkchstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm, const char *restrict format, va_list args); -/* - Function: chstrdup - Duplicate a chtype string - Parameters: chstr - String to duplicate - Returns: chtype * - Pointer to new (duplicated) string - - This function returns a new string of type chtype * that contains a - copy of the string in chstr. No errors are returned: if sufficient - memory is not available, the program terminates with an "Out of memory" - message. -*/ -extern chtype *chstrdup (const chtype *restrict chstr); - - /* Function: leftch - Print strings in chstr left-aligned Parameters: win - Window to use (should be curwin) diff --git a/src/move.c b/src/move.c index 353d73c..8382773 100644 --- a/src/move.c +++ b/src/move.c @@ -788,11 +788,11 @@ void merge_companies (map_val_t a, map_val_t b) mkchstr(chbuf, BUFSIZE, attr_highlight, 0, 0, 1, getmaxx(curwin) / 2, &width_aa, 1, "%s", company[aa].name); - chbuf_aa = chstrdup(chbuf); + chbuf_aa = xchstrdup(chbuf); mkchstr(chbuf, BUFSIZE, attr_highlight, 0, 0, 1, getmaxx(curwin) / 2, &width_bb, 1, "%s", company[bb].name); - chbuf_bb = chstrdup(chbuf); + chbuf_bb = xchstrdup(chbuf); mkchstr(chbuf, BUFSIZE, attr_normal, 0, 0, 1, getmaxx(curwin) / 2, &width, 1, @@ -1032,7 +1032,7 @@ void adjust_values (void) mkchstr(chbuf, BUFSIZE, attr_error_highlight, 0, 0, 1, w / 2, &width_amt, 1, "%N", company[which].share_price); - chbuf_amt = chstrdup(chbuf); + chbuf_amt = xchstrdup(chbuf); mkchstr(chbuf, BUFSIZE, attr_error_normal, 0, 0, 1, w / 2, &width, 1, diff --git a/src/utils.c b/src/utils.c index 3d9cfd5..c2a1dfd 100644 --- a/src/utils.c +++ b/src/utils.c @@ -487,6 +487,28 @@ char *xstrdup (const char *str) } +/***********************************************************************/ +// chstrdup: Duplicate a chtype buffer + +chtype *xchstrdup (const chtype *restrict chstr) +{ + const chtype *p; + int len; + chtype *ret; + + + // Determine chstr length, including ending NUL + for (len = 1, p = chstr; *p != '\0'; p++, len++) + ; + + ret = xmalloc(len * sizeof(chtype)); + memcpy(ret, chstr, len * sizeof(chtype)); + ret[len - 1] = '\0'; // Terminating NUL, just in case not present + + return ret; +} + + /***********************************************************************/ // xwcsdup: Duplicate a wide-character string, with checking diff --git a/src/utils.h b/src/utils.h index 6d0079f..7f7ada8 100644 --- a/src/utils.h +++ b/src/utils.h @@ -331,6 +331,19 @@ extern void *xmalloc (size_t size); extern char *xstrdup (const char *str); +/* + Function: xchstrdup - Duplicate a chtype string + Parameters: chstr - String to duplicate + Returns: chtype * - Pointer to new (duplicated) string + + This function returns a new string of type chtype * that contains a + copy of the string in chstr. No errors are returned: if sufficient + memory is not available, the program terminates with an "Out of memory" + message. +*/ +extern chtype *xchstrdup (const chtype *restrict chstr); + + /* Function: xwcsdup - Duplicate a wide-character string, with checking Parameters: str - String to duplicate