about summary refs log tree commit diff
path: root/Src/builtin.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2009-05-12 11:11:14 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2009-05-12 11:11:14 +0000
commitd1abd3e7cf53fc271e9d7c5de4f84ad3e6be42c7 (patch)
treedeeb332533ff117c6b66dce7cc2a6971eca8a0a9 /Src/builtin.c
parentc18b6c2c99b14301ac005e27a9472feed9a46eec (diff)
downloadzsh-d1abd3e7cf53fc271e9d7c5de4f84ad3e6be42c7.tar.gz
zsh-d1abd3e7cf53fc271e9d7c5de4f84ad3e6be42c7.tar.xz
zsh-d1abd3e7cf53fc271e9d7c5de4f84ad3e6be42c7.zip
26957: Fix some memory problems with read builtin
unposted: fix a WARN_CREATE_GLOBAL warning
Diffstat (limited to 'Src/builtin.c')
-rw-r--r--Src/builtin.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/Src/builtin.c b/Src/builtin.c
index d19ad01e2..86bb3bb9c 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -5085,16 +5085,16 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
     if (OPT_ISSET(ops,'d')) {
 	char *delimstr = OPT_ARG(ops,'d');
 #ifdef MULTIBYTE_SUPPORT
-	wint_t wc;
+	wint_t wi;
 
 	if (isset(MULTIBYTE)) {
 	    mb_metacharinit();
-	    (void)mb_metacharlenconv(delimstr, &wc);
+	    (void)mb_metacharlenconv(delimstr, &wi);
 	}
 	else
-	    wc = WEOF;
-	if (wc != WEOF)
-	    delim = (wchar_t)wc;
+	    wi = WEOF;
+	if (wi != WEOF)
+	    delim = (wchar_t)wi;
 	else
 	    delim = (wchar_t)((delimstr[0] == Meta) ?
 			      delimstr[1] ^ 32 : delimstr[0]);
@@ -5358,8 +5358,12 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
 		wc = (wchar_t)c;
 	    }
 	    if (ret != MB_INCOMPLETE) {
-		if (ret == MB_INVALID)
+		if (ret == MB_INVALID) {
 		    memset(&mbs, 0, sizeof(mbs));
+		    /* Treat this as a single character */
+		    wc = (wchar_t)c;
+		    laststart = bptr;
+		}
 		if (bslash && wc == delim) {
 		    bslash = 0;
 		    continue;
@@ -5450,9 +5454,10 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
 	}
 	signal_setmask(s);
 #ifdef MULTIBYTE_SUPPORT
-	if (c == EOF)
+	if (c == EOF) {
 	    gotnl = 1;
-	if (ret == MB_INCOMPLETE) {
+	    *bptr = '\0';	/* see below */
+	} else if (ret == MB_INCOMPLETE) {
 	    /*
 	     * We can only get here if there is an EOF in the
 	     * middle of a character... safest to keep the debris,