diff options
| -rw-r--r-- | include/conts/spvec.h | 7 | ||||
| -rw-r--r-- | tests/spvec.c | 3 | ||||
| -rw-r--r-- | tests/vec.c | 4 |
3 files changed, 14 insertions, 0 deletions
diff --git a/include/conts/spvec.h b/include/conts/spvec.h index 4fffb4a..d557fa8 100644 --- a/include/conts/spvec.h +++ b/include/conts/spvec.h @@ -193,6 +193,13 @@ static inline void SPVEC(shrink)(struct SPVEC_STRUCT *v, size_t n) static inline SPVEC_ITER SPVEC(begin)(struct SPVEC_STRUCT *v) { + if (v->n == 0) { + return (SPVEC_ITER) { + .i = 0, + .v = NULL + }; + } + return (SPVEC_ITER){ .i = 0, .v = SPVEC(at)(v, 0) diff --git a/tests/spvec.c b/tests/spvec.c index aa9b96c..b46bd88 100644 --- a/tests/spvec.c +++ b/tests/spvec.c @@ -21,6 +21,9 @@ int main() atexit(covsrv_destroy); #endif struct ints ints = ints_create(); + foreach(ints, iter, &ints) { + assert(false && "iterating empty spvec"); + } /* ensure stability before we do anything else */ assert(ints_reserve(&ints, 1)); diff --git a/tests/vec.c b/tests/vec.c index 1ed5f72..af36b5c 100644 --- a/tests/vec.c +++ b/tests/vec.c @@ -28,6 +28,10 @@ int main() #endif struct ints ints = ints_create(0); + foreach(ints, iter, &ints) { + assert(false && "iterating empty vec"); + } + for (int i = 0; i < 1000000; ++i) { if (!ints_append(&ints, i)) { fprintf(stderr, "failed appending %d to vec\n", i); |
