diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-09-06 21:15:23 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-09-06 21:15:23 -0700 |
commit | 1b5801edf62f8bfed9a2f88e88a0195518ba4976 (patch) | |
tree | f28c962166d31408728f22b855412e9475871a69 /linenoise | |
parent | d8e5052e3714fbede5b52a1706ed22d7e745d849 (diff) | |
download | txr-1b5801edf62f8bfed9a2f88e88a0195518ba4976.tar.gz txr-1b5801edf62f8bfed9a2f88e88a0195518ba4976.tar.bz2 txr-1b5801edf62f8bfed9a2f88e88a0195518ba4976.zip |
linenoise: use checked allocator for strdup.
* lib.c (chk_strdup_utf8): New function.
* lib.h (chk_strdup_utf8): Declared.
* linenoise/linenoise.c (chk_strdup_utf8): Declared.
(edit_history_next, linenoise, lino_hist_add): Use
chk_strdup_utf8 instead of strdup.
Diffstat (limited to 'linenoise')
-rw-r--r-- | linenoise/linenoise.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index f0311782..c28e7dd2 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -182,6 +182,7 @@ enum key_action { typedef unsigned char mem_t; mem_t *chk_malloc(size_t n); mem_t *chk_realloc(mem_t *old, size_t size); +char *chk_strdup_utf8(const char *str); static lino_t lino_list = { &lino_list, &lino_list }; static int atexit_registered = 0; /* Register atexit just 1 time. */ @@ -702,7 +703,7 @@ static void edit_history_next(lino_t *l, int dir) { /* Update the current history entry before to * overwrite it with the next one. */ free(l->history[l->history_len - 1 - l->history_index]); - l->history[l->history_len - 1 - l->history_index] = strdup(l->data); + l->history[l->history_len - 1 - l->history_index] = chk_strdup_utf8(l->data); /* Show the new entry */ l->history_index += (dir == LINENOISE_HISTORY_PREV) ? 1 : -1; if (l->history_index < 0) { @@ -1019,7 +1020,7 @@ char *linenoise(lino_t *ls, const char *prompt) if (count && ls->data[count-1] == '\n') ls->data[count-1] = '\0'; - return strdup(ls->data); + return chk_strdup_utf8(ls->data); } else { /* Interactive editing. */ if (enable_raw_mode(ls) == -1) @@ -1030,7 +1031,7 @@ char *linenoise(lino_t *ls, const char *prompt) printf("\n"); if (count == -1) return 0; - return strdup(ls->data); + return chk_strdup_utf8(ls->data); } } @@ -1132,7 +1133,7 @@ int lino_hist_add(lino_t *ls, const char *line) { /* Add an heap allocated copy of the line in the history. * If we reached the max length, remove the older line. */ - linecopy = strdup(line); + linecopy = chk_strdup_utf8(line); if (!linecopy) return 0; if (ls->history_len == ls->history_max_len) { free(ls->history[0]); |