summaryrefslogtreecommitdiffstats
path: root/inputstr.c
diff options
context:
space:
mode:
authorbapt <bapt@FreeBSD.org>2013-06-17 10:00:48 +0000
committerbapt <bapt@FreeBSD.org>2013-06-17 10:00:48 +0000
commit2b5579c9bdbbca29e7b2df1ee9a9e5d1cce2b06f (patch)
treed48b8f5f4c81e26e8dbb6597554286f1d6d53d3a /inputstr.c
parenta94245b3d36b447d1f761028da7e072210e64b43 (diff)
downloadFreeBSD-src-2b5579c9bdbbca29e7b2df1ee9a9e5d1cce2b06f.zip
FreeBSD-src-2b5579c9bdbbca29e7b2df1ee9a9e5d1cce2b06f.tar.gz
Update dialog to 1.2-20130523
Diffstat (limited to 'inputstr.c')
-rw-r--r--inputstr.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/inputstr.c b/inputstr.c
index aa719a1..a9e90c5 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:
OpenPOWER on IntegriCloud