segfault -> assertion

This commit is contained in:
Neil 2023-02-04 19:10:59 -08:00
parent 745e7c3167
commit 2fd07c2329
1 changed files with 2 additions and 0 deletions

View File

@ -27,6 +27,7 @@ int pair_to_natural(const char *s, const char *const e, uint32_t *const n) {
int pair_is_equal(struct pair x, struct pair y) {
assert(x.a <= x.b && y.a <= y.b);
if(!x.a) return !y.a;
if(!y.a) return 0;
if(x.b - x.a != y.b - y.a) return 0;
while(x.a < x.b) { if(*x.a != *y.a) return 0; x.a++, y.a++; }
return 1;
@ -35,6 +36,7 @@ int pair_is_equal(struct pair x, struct pair y) {
int pair_is_string(struct pair x, const char *y) {
assert(x.a <= x.b);
if(!x.a) return !y;
if(!y) return 0;
while(x.a < x.b) { if(*x.a != *y || !*y) return 0; x.a++, y++; }
return !*y;
}