D1251.bash5-check-printf.patch (3385B)
1 From 679f9db5a6d70784bd7ee3a1d947ab10f71623b6 Mon Sep 17 00:00:00 2001 2 From: Koichi Murase <myoga.murase@gmail.com> 3 Date: Tue, 4 Feb 2020 19:01:57 +0800 4 Subject: [PATCH] bash-5.0.11: check printf \uXXXX 5 6 --- 7 builtins/printf.def | 14 ++++++++------ 8 lib/sh/unicode.c | 12 ++++++++---- 9 2 files changed, 16 insertions(+), 10 deletions(-) 10 11 diff --git a/builtins/printf.def b/builtins/printf.def 12 index bc6ef57..164d80c 100644 13 --- a/builtins/printf.def 14 +++ b/builtins/printf.def 15 @@ -414,7 +414,7 @@ printf_builtin (list) 16 modstart = fmt; 17 while (*fmt && strchr (LENMODS, *fmt)) 18 fmt++; 19 - 20 + 21 if (*fmt == 0) 22 { 23 builtin_error (_("`%s': missing format character"), start); 24 @@ -814,7 +814,7 @@ printstr (fmt, string, len, fieldwidth, precision) 25 26 return (ferror (stdout) ? -1 : 0); 27 } 28 - 29 + 30 /* Convert STRING by expanding the escape sequences specified by the 31 POSIX standard for printf's `%b' format string. If SAWC is non-null, 32 perform the processing appropriate for %b arguments. In particular, 33 @@ -913,7 +913,7 @@ tescape (estart, cp, lenp, sawc) 34 } 35 break; 36 #endif 37 - 38 + 39 case '\\': /* \\ -> \ */ 40 *cp = c; 41 break; 42 @@ -996,7 +996,7 @@ bexpand (string, len, sawc, lenp) 43 *r++ = mbch[mbind]; 44 #else 45 *r++ = c; 46 -#endif 47 +#endif 48 } 49 50 *r = '\0'; 51 @@ -1070,7 +1070,7 @@ vbprintf (format, va_alist) 52 if (strlen (vbuf) != vblen) 53 internal_error ("printf:vbprintf: vblen (%d) != strlen (vbuf) (%d)", vblen, (int)strlen (vbuf)); 54 #endif 55 - 56 + 57 return (blen); 58 } 59 60 @@ -1198,7 +1198,7 @@ getuintmax () 61 62 errno = 0; 63 ret = strtoumax (garglist->word->word, &ep, 0); 64 - 65 + 66 if (*ep) 67 { 68 sh_invalidnum (garglist->word->word); 69 @@ -1262,12 +1262,14 @@ asciicode () 70 slen = strlen (garglist->word->word+1); 71 wc = 0; 72 mblength = mbtowc (&wc, garglist->word->word+1, slen); 73 +//printf("MBLENGTH=%d;wc=%d\n",(int)mblength,(int)wc); 74 if (mblength > 0) 75 ch = wc; /* XXX */ 76 else 77 #endif 78 ch = (unsigned char)garglist->word->word[1]; 79 80 +//if(mblength==-1)printf("MBLENGTH=%d;wc=%d;ch=%d\n",(int)mblength,(int)wc,(int)ch); 81 garglist = garglist->next; 82 return (ch); 83 } 84 diff --git a/lib/sh/unicode.c b/lib/sh/unicode.c 85 index fe13c4a..79f8aeb 100644 86 --- a/lib/sh/unicode.c 87 +++ b/lib/sh/unicode.c 88 @@ -132,7 +132,7 @@ u32tochar (x, s) 89 s[3] = x & 0xFF; 90 } 91 s[l] = '\0'; 92 - return l; 93 + return l; 94 } 95 96 int 97 @@ -291,18 +291,22 @@ u32cconv (c, s) 98 } 99 100 /* NL_LANGINFO and locale_charset used when setting locale_utf8locale */ 101 - 102 + 103 /* If we have a UTF-8 locale, convert to UTF-8 and return converted value. */ 104 +{FILE* f = fopen("/dev/tty","w"); 105 n = u32toutf8 (c, s); 106 +fprintf(f,"C%x,N%d\n\n",c,n); 107 +fclose(f); 108 if (utf8locale) 109 return n; 110 +} 111 112 /* If the conversion is not supported, even the ASCII requested above, we 113 bail now. Currently we return the UTF-8 conversion. We could return 114 u32tocesc(). */ 115 if (localconv == (iconv_t)-1) 116 return n; 117 - 118 + 119 optr = obuf; 120 obytesleft = sizeof (obuf); 121 iptr = s; 122 @@ -312,7 +316,7 @@ u32cconv (c, s) 123 124 if (iconv (localconv, (ICONV_CONST char **)&iptr, &sn, &optr, &obytesleft) == (size_t)-1) 125 { 126 - /* You get ISO C99 escape sequences if iconv fails */ 127 + /* You get ISO C99 escape sequences if iconv fails */ 128 n = u32tocesc (c, s); 129 return n; 130 } 131 -- 132 2.21.0 133