Add Strlen(), a strlen(3) that panics if string is stupid long and returns unsigned.

First batch of changes to use it to suppress warnings.
This commit is contained in:
nhkeni
2022-03-06 20:23:04 -05:00
parent 1e31fee0df
commit ff1289e828
16 changed files with 45 additions and 32 deletions

View File

@@ -24,6 +24,7 @@
char * strip_newline (char *)
char * stripchars (char *, const char *, const char *)
char * stripdigits (char *)
unsigned Strlen (const char *str)
char * eos (char *)
boolean str_end_is (const char *, const char *)
int str_lines_maxlen (const char *)
@@ -228,6 +229,16 @@ eos(register char *s)
return s;
}
/* like strlen(3) but returns unsigned and panics if string is unreasonably long */
unsigned
Strlen(const char *str){
size_t len = strnlen(str, LARGEST_INT);
if (len == LARGEST_INT)
panic("string too long");
return (unsigned) len;
}
/* determine whether 'str' ends in 'chkstr' */
boolean
str_end_is(const char *str, const char *chkstr)