From: erik quanstrom <quanstro@quanstro.net>
To: 9fans@9fans.net
Subject: [9fans] dofmt.c patch
Date: Fri, 1 Jul 2011 22:13:14 -0400 [thread overview]
Message-ID: <8ebc8bbdc761a4b89f618c0532934246@ladd.quanstro.net> (raw)
this got lost in a large patch that didn't get accepted, and i just turned it up. i'd hate for
anyone else to trip over the same troubles. this fixes
- sneaky UTFmax dependencies
- a bug if %r is given with no matching format for rune r, where r>127.
- %, interacting badly with 0 padding.
- bad formatting of %#b.
/n/sources/plan9//sys/src/libc/fmt/dofmt.c:415,426 - dofmt.c:415,431
*p-- = '0';
n = 1;
}
- for(w = f->prec; n < w && p > buf+3; n++)
+ for(w = f->prec; n < w && p > buf+4; n++){
+ if((fl & FmtComma) && n % 4 == 3){
+ *p-- = ',';
+ n++;
+ }
*p-- = '0';
+ }
if(neg || (fl & (FmtSign|FmtSpace)))
n++;
if(fl & FmtSharp){
- if(base == 16)
+ if(base == 16 || base == 2)
n += 2;
else if(base == 8){
if(p[1] == '0')
/n/sources/plan9//sys/src/libc/fmt/dofmt.c:430,443 - dofmt.c:435,453
}
}
if((fl & FmtZero) && !(fl & (FmtLeft|FmtPrec))){
- for(w = f->width; n < w && p > buf+3; n++)
+ for(w = f->width; n < w && p > buf+4; n++){
+ if((fl & FmtComma) && n % 4 == 3){
+ *p-- = ',';
+ n++;
+ }
*p-- = '0';
+ }
f->width = 0;
}
if(fl & FmtSharp){
- if(base == 16)
+ if(base == 16 || base == 2)
*p-- = f->r;
- if(base == 16 || base == 8)
+ if(base == 16 || base == 8 || base == 2)
*p-- = '0';
}
if(neg)
/n/sources/plan9//sys/src/libc/fmt/dofmt.c:512,523 - dofmt.c:522,534
int
_badfmt(Fmt *f)
{
- char x[3];
+ char x[2+UTFmax];
+ int n;
x[0] = '%';
- x[1] = f->r;
- x[2] = '%';
- f->prec = 3;
- _fmtcpy(f, x, 3, 3);
+ n = 1 + runetochar(x+1, (Rune*)&f->r);
+ x[n++] = '%';
+ f->prec = n;
+ _fmtcpy(f, x, n, n);
return 0;
}
- erik
reply other threads:[~2011-07-02 2:13 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8ebc8bbdc761a4b89f618c0532934246@ladd.quanstro.net \
--to=quanstro@quanstro.net \
--cc=9fans@9fans.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).