On 22 Apr 2024, at 14:13, Ruediger Pluem <[email protected]> wrote:
>> @@ -322,7 +287,17 @@ APR_DECLARE(int) apr_buffer_ncmp(const a
>> return 1;
>> }
>
> There was a proposal from Yann to simplify the above block to
>
> if (!src) {
> return dst ? 1 : 0;
> }
> if (!dst) {
> return -1;
> }
apr_buffer_ncmp has been removed. It was originally a null supporting comparison
function alongside a non null supporting comparison function, but now that the
buffer could contain NULL, it became overkill.
>> @@ -379,19 +354,19 @@ APR_DECLARE(char *) apr_buffer_pstrncat(
>> strncpy(dst, sep, seplen);
>> dst += seplen;
>> }
>> -
>> - if (src->size < 0) {
>> - strncpy(dst, src->d.str, (apr_size_t)((-src->size) - 1));
>> - dst += (-src->size) - 1;
>> +
>> + if (src->zero_terminated) {
>> + strncpy(dst, src->d.str, src->size);
>> + dst += src->size;
>> }
>
> Can't we remove the above condition at all and do a
>
> memcpy(dst, src->d.mem, src->size + src->zero_terminated);
>
> below in the if (APR_BUFFER_NONE == flags) block?
Alas no, the encoding is only applied if the buffer contains binary data.
I did replace the strncpy, as the terminating zero is written at the end.
http://svn.apache.org/viewvc?rev=1917268&view=rev
>
>> else {
>> if (APR_BUFFER_NONE == flags) {
>> - memcpy(dst, src->d.mem, (apr_size_t)src->size);
>> + memcpy(dst, src->d.mem, src->size);
>> }
>> else if (APR_BUFFER_BASE64 == flags) {
>> apr_size_t b64len;
>>
>> - if (APR_SUCCESS != apr_encode_base64(dst, src->d.mem,
>> (apr_size_t)src->size,
>> + if (APR_SUCCESS != apr_encode_base64(dst, src->d.mem,
>> src->size,
>> APR_ENCODE_NONE,
>> &b64len)) {
>> return NULL;
>> }
>>
Regards,
Graham
--