diff options
Diffstat (limited to 'inputstr.c')
-rw-r--r-- | inputstr.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/inputstr.c b/inputstr.c index aa719a1379a59..a9e90c59da5fd 100644 --- a/inputstr.c +++ b/inputstr.c @@ -1,9 +1,9 @@ /* - * $Id: inputstr.c,v 1.70 2011/10/20 23:42:49 tom Exp $ + * $Id: inputstr.c,v 1.72 2012/12/30 22:11:37 tom Exp $ * * inputstr.c -- functions for input/display of a string * - * Copyright 2000-2010,2011 Thomas E. Dickey + * Copyright 2000-2011,2012 Thomas E. Dickey * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License, version 2.1 @@ -308,13 +308,17 @@ dlg_count_wchars(const char *string) size_t code; wchar_t *temp = dlg_calloc(wchar_t, len + 1); - cache.string[part] = '\0'; - memset(&state, 0, sizeof(state)); - code = mbsrtowcs(temp, &src, (size_t) part, &state); - cache.i_len = ((int) code >= 0) ? wcslen(temp) : 0; - cache.string[part] = save; - free(temp); - save_cache(&cache, string); + if (temp != 0) { + cache.string[part] = '\0'; + memset(&state, 0, sizeof(state)); + code = mbsrtowcs(temp, &src, (size_t) part, &state); + cache.i_len = ((int) code >= 0) ? wcslen(temp) : 0; + cache.string[part] = save; + free(temp); + save_cache(&cache, string); + } else { + cache.i_len = 0; + } } result = (int) cache.i_len; } else @@ -375,8 +379,9 @@ dlg_find_index(const int *list, int limit, int to_find) for (result = 0; result <= limit; ++result) { if (to_find == list[result] || result == limit - || to_find < list[result + 1]) + || ((result < limit) && (to_find < list[result + 1]))) { break; + } } return result; } @@ -529,7 +534,7 @@ dlg_edit_string(char *string, int *chr_offset, int key, int fkey, bool force) edit = force; break; case DLGK_GRID_LEFT: - if (*chr_offset) + if (*chr_offset && offset > 0) *chr_offset = indx[offset - 1]; break; case DLGK_GRID_RIGHT: |