History

io-peek: special-case a single rune/utf8 to not overread

Sigrid Solveig Haflínudóttir committed 3 months ago

Commit 782c2661 parent 4212b4f1 file · +5 −2Browse files

Unified · Split

src/io.c+5−2
@@ -270,12 +270,15 @@ fetch_data(sl_v *args, int nargs, bool peek) · 269 unmodified lines
270270 buf += got;
271271 }else if(peek){
272272 char *data = (char*)(isrune ? buf+n : buf);
273− got = ios_peek(s, (u8int*)data, n);
273+ Rune r;
274+ if(nem == 1 && (got = ios_peekrune(s, &r)) == 1)
275+ got = runetochar(data, &r);
276+ else
277+ got = ios_peek(s, (u8int*)data, n);
274278 usize nr, nb, left = got;
275279 for(nr = nb = 0; left > 0 && nr < nem; nr++){
276280 if(!fullrune(data, left))
277281 break;
278− Rune r;
279282 int bc = chartorune(&r, data);
280283 if(r == Runeerror)
281284 bthrow(error(sl_errio, "invalid rune"));

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t