str, bench: three checks that guard nothing

sinit sets s->n = 0 as its first statement and no failure path restores
it, so stail's sclear after a failed sinit could never change anything;
say so in sinit's comment instead, where the contract belongs.  bench
compared a uintmax_t against UINT64_MAX and a size_t against UINT64_MAX,
both constant on any host this builds for.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-18 16:14:16 +09:00
parent 4802b6593e
commit bdf05e3c4a
2 changed files with 5 additions and 5 deletions

6
str.c
View File

@@ -1,7 +1,8 @@
#include "dat.h"
#include "fn.h"
/* Fills s from n bytes of UTF-8; whole, valid, and at most Maxrunes. */
/* Fills s from n bytes of UTF-8; whole, valid, and at most Maxrunes.
* Anything else leaves s empty. */
int
sinit(Str *s, char *src, int n)
{
@@ -35,8 +36,7 @@ stail(Str *s, char *src, int n)
nr = utfnlen(src, n);
for(p = src; nr > Maxrunes; nr--)
p += chartorune(&r, p);
if(!sinit(s, p, n - (p - src)))
sclear(s);
sinit(s, p, n - (p - src));
}
void