Skip to content

Commit

Permalink
apr_buffer: Advance buffer during apr_buffer_pstrncat().
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1920293 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
minfrin committed Aug 30, 2024
1 parent 0b10ac3 commit f1886c4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions buffer/apr_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ APR_DECLARE(char *) apr_buffer_pstrncat(apr_pool_t *p, const apr_buffer_t *buf,
else {
if (APR_BUFFER_PLAIN == flags) {
memcpy(dst, src->d.mem, src->size);
dst += src->size;
}
else if (APR_BUFFER_BASE64 == flags) {
apr_size_t b64len;
Expand Down
2 changes: 1 addition & 1 deletion test/abts_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const struct testlist {
{testuri},
{testuuid},
{testbuckets},
{testbuffer},
{testpass},
{testbase64},
{testmd4},
Expand All @@ -94,7 +95,6 @@ const struct testlist {
{testsiphash},
{testjson},
{testjose},
{testbuffer},
{testldap}
};

Expand Down
14 changes: 8 additions & 6 deletions test/testbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ static void test_buffers(abts_case *tc, void *data)
apr_pool_t *pool;
apr_array_header_t *vals;

apr_buffer_t src[2];
apr_buffer_t src[4];
apr_buffer_t *dst;

char *str;
Expand All @@ -180,11 +180,13 @@ static void test_buffers(abts_case *tc, void *data)
/* populate our source buffers */
apr_buffer_mem_set(&src[0], test_memory, sizeof(test_memory));
apr_buffer_str_set(&src[1], test_string, strlen(test_string));
apr_buffer_mem_set(&src[2], test_memory, sizeof(test_memory));
apr_buffer_str_set(&src[3], test_string, strlen(test_string));

/* duplicate the source buffers, allocating memory from a pool */
vals = apr_array_make(pool, 2, sizeof(apr_buffer_t));
apr_buffer_arraydup((apr_buffer_t **)(&vals->elts), src, test_buffers_palloc, pool, 2);
vals->nelts = 2;
vals = apr_array_make(pool, 4, sizeof(apr_buffer_t));
apr_buffer_arraydup((apr_buffer_t **)(&vals->elts), src, test_buffers_palloc, pool, 4);
vals->nelts = 4;

dst = apr_array_pop(vals);

Expand All @@ -201,10 +203,10 @@ static void test_buffers(abts_case *tc, void *data)
ABTS_ASSERT(tc, "buffer copy fail",
!apr_buffer_cmp(dst, &src[1]));

str = apr_buffer_pstrncat(pool, &src[0], 2, "; ", APR_BUFFER_BASE64, &len);
str = apr_buffer_pstrncat(pool, &src[0], 4, "; ", APR_BUFFER_BASE64, &len);

ABTS_ASSERT(tc, "buffer strcat fail",
!strcmp(str, "AQIDBA==; Hello"));
!strcmp(str, "AQIDBA==; Hello; AQIDBA==; Hello"));

apr_pool_destroy(pool);
}
Expand Down

0 comments on commit f1886c4

Please sign in to comment.