On 06/28/24 09:55AM, NRK wrote:
> > +void
> > +tbufnew(size_t siz) {
>
> Seems pointless noise. Just do `siz ? (siz*2) : 128` when extending.
fixed
> > + tbuf.buf = (char *)xmalloc(siz);
>
> Don't cast malloc: https://c-faq.com/malloc/mallocnocast.html
fixed
> > +size_t
> > +tbuflen(void) {
> > + return tbuf.len;
> > +}
>
> I'd just make the object available instead of dancing around.
st.c doesn't seem to expose any non-static globals & I don't want to
add the first.
> Braces for functions also should go on their own line.
>
> > + if (tbuf.siz - tbuf.len < n) {
> > + tbuf.siz *= 2;
fixed
> What guarantees that `siz * 2` will make enough space for `n`? I don't
> see any, which makes the memcpy below a buffer overflow.
>
> > + tbuf.buf = xrealloc(tbuf.buf, tbuf.siz);
fixed
> I'm highly skeptical of this. If the other end is not able to keep up
> that doesn't mean we should unboundedly keep hogging up memory.
My understanding of the problem has changed, as you may see in the new
commit message.
Try pasting one-million bytes from your clipboard into mainline st now.
It will lock up.
Jeremy
..
......
......
....... ...
........ ... ......
.'.......... .. ..........
.,''...... .... ..............
;;,.............. ..............
.;;'...... ... .';c:;'.......'
.;;,,''........ .;lc,...,.......,.
.;:odolol;.'...'::c,.............;.
.::::clxxx:,'',cc;;;,','........',.
cllc:::odk' .':,;::dko;........'..l.
.c:ckxol;;l. .'.;;:lc;'......'.'.::.
c;'','...c ,'..,,,'.. .......'.:,
.:,.. .', ,'... .......'.'..
;,... ., ,.'.. ........'.,..
::'.. .' .,.,'.. ........',.',.
.d,;....':. ..;;,.'............,,'.,
.k;:;...'ol;;:,.. ..'.........',,o'.
.cc:;'..,;'... .........',,,0kc'...
o::;,'....................',,':XKxlc:;,.
. ...':kk:c;,ccc;loool:c::,......',,,c:xKkoolcc.
....,;::cclllodk0K0o;;',...:ddoccl,....''',,,,cl:,okdolcc.
...'''',;:::::cclldxxxxO:...',:dkxxxl:.....,''''';dx:;,cOoocc:.
.';,',,,,,,,;,;;:clodxc'c,...,cdd:'... ....';,''';dkd;'c,dkdlc::.
',;,;,,,,,,,,,,;;;:ldlc;;,;,;ddxo:'....'';::,,;lxOdc;,'c:xdlc:::.
.';;;;,,,,,,,,,,,,,::. .cc'..'..;locclllc:;cd00xl;;,'.lolc:::;;.
'':;;;,,,,,,,,,,,,,'. ..',:,'..,..'K0Okxxxk0K0ko:;,',;;c:::;;;;;.
',c;;,,,,,,,,,,,,,. ..,c;:o. ., .'OXXXNK0Okxoc;;;;:::;;;;,,,,,,.
,;c;;,,,,,,,,,;;,. ..,lllxd. .' .',kOkOolcc:::;;;;;;;;,,,,,,,,,.
;;l;;;;;;,;;;;;;. ...:lccl; .'....,..:d::codo;;;;;;;;,,,;,,,,,,.
l:l::;;;;;;;;:;. ...':,'':..,. ...;.'ldoddol:;,,,,,;,,,,;,,,,,,.
ocl:::;;;;;:::. ...':;..''.,c..;..c,;collll:,,,,,,;,,,,;;,,,,,,.
cdcc:;;;;:::;. ....;;'..,l:lkclk,.:;,c:ccc:,,,,,,,,,,,,;;,,,,,,.
:ool:;:::::,. ....',,....''.,:,xOd:cd:;;;:;,,,,,,,,,,,,;;;,,,,,.
;;ll;;::;:' ......',........,;,cxdol:,',,,''''','''''',,,,,'','.
Received on Sat Jun 29 2024 - 05:00:41 CEST