X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Fecoli_strvec.c;fp=lib%2Fecoli_strvec.c;h=132183d366654d59163e545667df6f6eb8d4d2a8;hb=044f2e33e83ec36df6601e3950820d07facde0a7;hp=bd23d98c3b754a21b0b818819486c0f2c3ee37bf;hpb=2f6e2fbedc023ad3579b62181fa4b5637494aa5b;p=protos%2Flibecoli.git diff --git a/lib/ecoli_strvec.c b/lib/ecoli_strvec.c index bd23d98..132183d 100644 --- a/lib/ecoli_strvec.c +++ b/lib/ecoli_strvec.c @@ -42,18 +42,18 @@ int ec_strvec_add(struct ec_strvec *strvec, const char *s) new_vec = ec_realloc(strvec->vec, sizeof(*strvec->vec) * (strvec->len + 1)); if (new_vec == NULL) - return -ENOMEM; + return -1; strvec->vec = new_vec; elt = ec_malloc(sizeof(*elt)); if (elt == NULL) - return -ENOMEM; + return -1; elt->str = ec_strdup(s); if (elt->str == NULL) { ec_free(elt); - return -ENOMEM; + return -1; } elt->refcnt = 1; @@ -69,6 +69,9 @@ struct ec_strvec *ec_strvec_from_array(const char * const *strarr, size_t i; strvec = ec_strvec(); + if (strvec == NULL) + goto fail; + for (i = 0; i < n; i++) { if (ec_strvec_add(strvec, strarr[i]) < 0) goto fail; @@ -342,6 +345,16 @@ static int ec_strvec_testcase(void) free(buf); buf = NULL; + ec_strvec_del_last(strvec); + strvec2 = EC_STRVEC("0"); + if (strvec2 == NULL) { + EC_TEST_ERR("cannot create strvec from array\n"); + goto fail; + } + testres |= EC_TEST_CHECK(ec_strvec_cmp(strvec, strvec2) == 0, + "strvec and strvec2 should be equal\n"); + ec_strvec_free(strvec2); + f = open_memstream(&buf, &buflen); if (f == NULL) goto fail;