Fix bugs and make code tinier

- Fixed bug where stdio eof wasn't being sticky
- Fixed bug where fseeko() wasn't clearing eof state
- Removed assert() usage from libc favoring _unassert() / _npassert()
This commit is contained in:
Justine Tunney 2022-10-09 22:38:28 -07:00
parent 9b7c8db846
commit d5910e2673
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
115 changed files with 510 additions and 290 deletions

View file

@ -126,7 +126,7 @@ int BLAKE2B256_Update(struct Blake2b *b2b, const void *in_data, size_t len) {
return 0;
}
// More input remains therefore we must have filled |b2b->block|.
assert(b2b->block_used == BLAKE2B_CBLOCK);
_unassert(b2b->block_used == BLAKE2B_CBLOCK);
Blake2bTransform(b2b, b2b->block.words, BLAKE2B_CBLOCK,
/*is_final_block=*/0);
b2b->block_used = 0;

View file

@ -51,7 +51,7 @@ static unsigned _getcachesize_cpuid4(int type, int level) {
* @return size in bytes, or 0 if unknown
*/
unsigned _getcachesize(int type, int level) {
assert(1 <= type && type <= 3);
assert(level >= 1);
_unassert(1 <= type && type <= 3);
_unassert(level >= 1);
return _getcachesize_cpuid4(type, level);
}

View file

@ -70,6 +70,6 @@ char *strchr(const char *s, int c) {
} else {
r = strchr_pure(s, c);
}
assert(!r || *r || !(c & 255));
_unassert(!r || *r || !(c & 255));
return (char *)r;
}

View file

@ -68,6 +68,6 @@ char *strchrnul(const char *s, int c) {
} else {
r = strchrnul_pure(s, c);
}
assert((*r & 255) == (c & 255) || !*r);
_unassert((*r & 255) == (c & 255) || !*r);
return (char *)r;
}

View file

@ -17,9 +17,9 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/assert.h"
#include "libc/intrin/bits.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/bits.h"
#include "libc/str/str.h"
static noasan size_t strnlen_x64(const char *s, size_t n, size_t i) {
@ -52,7 +52,7 @@ noasan size_t strnlen(const char *s, size_t n) {
for (;; ++i) {
if (i == n || !s[i]) break;
}
assert(i == n || (i < n && !s[i]));
_unassert(i == n || (i < n && !s[i]));
if (IsAsan()) __asan_verify(s, i);
return i;
}

View file

@ -32,6 +32,6 @@ noasan size_t strnlen16(const char16_t *s, size_t n) {
for (i = 0;; ++i) {
if (i == n || !s[i]) break;
}
assert(i == n || (i < n && !s[i]));
_unassert(i == n || (i < n && !s[i]));
return i;
}

View file

@ -56,6 +56,6 @@ noasan size_t strnlen_s(const char *s, size_t n) {
for (;; ++i) {
if (i == n || !s[i]) break;
}
assert(i == n || (i < n && !s[i]));
_unassert(i == n || (i < n && !s[i]));
return i;
}

View file

@ -42,6 +42,6 @@
* @note if dest is NULL, count has to be zero
*/
size_t strxfrm(char *dest, const char *src, size_t count) {
assert(dest == NULL ? count == 0 : 1);
_unassert(dest == NULL ? count == 0 : 1);
return strlcpy(dest, src, count);
}