fix: harden small core containers

This commit is contained in:
2026-08-12 15:54:16 +09:00
parent cec62cc40f
commit 103f2ec448
11 changed files with 136 additions and 18 deletions

5
str.c
View File

@@ -7,6 +7,8 @@ sinit(Str *s, char *src, int n)
int len;
s->n = 0;
if(n < 0 || (n > 0 && src == nil))
return;
while(n > 0 && s->n < Maxrunes){
if(!fullrune(src, n))
break;
@@ -28,8 +30,9 @@ sclear(Str *s)
void
sputr(Str *s, Rune r)
{
/* Str is a capped value; appends at capacity leave it unchanged. */
if(s->n >= Maxrunes)
die("sputr overflow");
return;
s->r[s->n++] = r;
}