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
270 buf += got;270 buf += got;
271 }else if(peek){271 }else if(peek){
272 char *data = (char*)(isrune ? buf+n : buf);272 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);
274 usize nr, nb, left = got;278 usize nr, nb, left = got;
275 for(nr = nb = 0; left > 0 && nr < nem; nr++){279 for(nr = nb = 0; left > 0 && nr < nem; nr++){
276 if(!fullrune(data, left))280 if(!fullrune(data, left))
277 break;281 break;
278 Rune r;
279 int bc = chartorune(&r, data);282 int bc = chartorune(&r, data);
280 if(r == Runeerror)283 if(r == Runeerror)
281 bthrow(error(sl_errio, "invalid rune"));284 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