Index: ossp-pkg/var/var.c RCS File: /v/ossp/cvs/ossp-pkg/var/var.c,v rcsdiff -q -kk '-r1.44' '-r1.45' -u '/v/ossp/cvs/ossp-pkg/var/var.c,v' 2>/dev/null --- var.c 2001/12/12 16:52:56 1.44 +++ var.c 2001/12/12 17:18:55 1.45 @@ -1965,5 +1965,18 @@ lookup, lookup_context, force_expand, &output, 0, 0); *result = (char *)output.begin; *result_len = output.end - output.begin; - return (rc >= 0) ? VAR_OK : rc; + if (rc >= 0) + { + if (!tokenbuf_append(&output, "\0", 1)) + { + tokenbuf_free(&output); + return VAR_ERR_OUT_OF_MEMORY; + } + --output.end; + rc = VAR_OK; + } + + *result = (char *)output.begin; + *result_len = output.end - output.begin; + return rc; } Index: ossp-pkg/var/var.pod RCS File: /v/ossp/cvs/ossp-pkg/var/var.pod,v rcsdiff -q -kk '-r1.13' '-r1.14' -u '/v/ossp/cvs/ossp-pkg/var/var.pod,v' 2>/dev/null --- var.pod 2001/12/12 16:51:20 1.13 +++ var.pod 2001/12/12 17:18:55 1.14 @@ -166,19 +166,21 @@ A pointer to a character pointer in which the location of the expanded text buffer will be stored. The result buffer will be allocated by var_expand() using the system call malloc(3), thus it is the caller's -responsibility to free(3) that buffer once it is not used anymore. +responsibility to free(3) that buffer once it is not used anymore. The +result buffer will be terminated by null byte, which is not included +in the "result_len" counter. If var_expand() fails with an error, "result" will point to "input". -The only exception is the VAR_ERR_INVALID_ARGUMENT error, in which -case "result" is not modified. +The only exceptions are the VAR_ERR_INVALID_ARGUMENT +VAR_ERR_OUT_OF_MEMORY errors, in which case "result" is undefined. =item size_t *result_len A pointer to the location in which the length of the expanded text buffer will be stored. If var_expand() fails with an error -- with the -exception of VAR_ERR_INVALID_ARGUMENT --, "result_len" will contain -the number of characters that have been consumed from "input" before -the error occured. +exception of VAR_ERR_INVALID_ARGUMENT and VAR_ERR_OUT_OF_MEMORY --, +"result_len" will contain the number of characters that have been +consumed from "input" before the error occured. =item var_cb_t lookup Index: ossp-pkg/var/var_test.c RCS File: /v/ossp/cvs/ossp-pkg/var/var_test.c,v rcsdiff -q -kk '-r1.23' '-r1.24' -u '/v/ossp/cvs/ossp-pkg/var/var_test.c,v' 2>/dev/null --- var_test.c 2001/12/12 16:51:20 1.23 +++ var_test.c 2001/12/12 17:18:55 1.24 @@ -143,7 +143,7 @@ { "${ARRAY[$NUMEXP-1]}", "entry0" }, { "${ARRAY[${UNDEFINED}-1]}", "${ARRAY[${UNDEFINED}-1]}" }, { "${ARRAY[5/(${UNDEFINED})]}", "${ARRAY[5/(${UNDEFINED})]}" }, - { ":[${ARRAY}-]:", ":entry0-entry1-entry2-entry3-:" } + { "[${ARRAY}-]", "entry0-entry1-entry2-entry3-" } }; char *tmp; size_t tmp_len;