aboutsummaryrefslogtreecommitdiffstats
path: root/builtin.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2013-07-04 11:40:00 +0300
committerArnold D. Robbins <arnold@skeeve.com>2013-07-04 11:40:00 +0300
commit71cc2e70847d5a3b99c249fa609ea6ba8b1a00d6 (patch)
tree8d5d238bb671fff295f5ecee19be56153c470166 /builtin.c
parent96cb55baaa352714943b94e73cbf94866250628d (diff)
downloadegawk-71cc2e70847d5a3b99c249fa609ea6ba8b1a00d6.tar.gz
egawk-71cc2e70847d5a3b99c249fa609ea6ba8b1a00d6.tar.bz2
egawk-71cc2e70847d5a3b99c249fa609ea6ba8b1a00d6.zip
Fix for %c in multibyte locale + new tests.
Diffstat (limited to 'builtin.c')
-rw-r--r--builtin.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/builtin.c b/builtin.c
index ba1d8dcb..b8e24cb3 100644
--- a/builtin.c
+++ b/builtin.c
@@ -1097,6 +1097,7 @@ out0:
* used to work? 6/2003.)
*/
cp = arg->stptr;
+ prec = 1;
#if MBS_SUPPORT
/*
* First character can be multiple bytes if
@@ -1108,17 +1109,14 @@ out0:
memset(& state, 0, sizeof(state));
count = mbrlen(cp, arg->stlen, & state);
- if (count == 0
- || count == (size_t)-1
- || count == (size_t)-2)
- goto out2;
- prec = count;
- goto pr_tail;
+ if (count > 0) {
+ prec = count;
+ /* may need to increase fw so that padding happens, see pr_tail code */
+ if (fw > 0)
+ fw += count - 1;
+ }
}
-out2:
- ;
#endif
- prec = 1;
goto pr_tail;
case 's':
need_format = false;
@@ -1421,9 +1419,14 @@ mpf1:
copy_count = prec;
if (fw == 0 && ! have_prec)
;
- else if (gawk_mb_cur_max > 1 && (cs1 == 's' || cs1 == 'c')) {
- assert(cp == arg->stptr || cp == cpbuf);
- copy_count = mbc_byte_count(arg->stptr, prec);
+ else if (gawk_mb_cur_max > 1) {
+ if (cs1 == 's') {
+ assert(cp == arg->stptr || cp == cpbuf);
+ copy_count = mbc_byte_count(arg->stptr, prec);
+ }
+ /* prec was set by code for %c */
+ /* else
+ copy_count = prec; */
}
bchunk(cp, copy_count);
while (fw > prec) {