[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: wget2 | Draft: Small fixes (!505)
From: |
@rockdaboot |
Subject: |
Re: wget2 | Draft: Small fixes (!505) |
Date: |
Sun, 26 Jun 2022 11:48:18 +0000 |
Tim Rühsen started a new discussion on libwget/buffer.c:
https://gitlab.com/gnuwget/wget2/-/merge_requests/505#note_1005679321
> char *start = buf->data;
> char *end = start + buf->length - 1;
>
> - if (isspace(*end)) {
> + /* Accessing `start - 1` is undefined so leave if `start ==
> end` */
> + if ((start < end) && isspace(*end)) {
The whole function could be simplified into
```
char *wget_buffer_trim(wget_buffer *buf)
{
if (unlikely(!buf))
return NULL;
while (buf->length > 0 && isspace(buf->data[buf->length - 1])) {
buf->length--;
}
buf->data[buf->length] = 0;
size_t spaces = 0;
while (buf->length > 0 && isspace(buf->data[spaces]))
spaces++;
if (spaces) {
buf->length -= spaces;
/* Include trailing 0 */
memmove(buf->data, buf->data + spaces, buf->length + 1);
}
return buf->data;
}
```
I pushed it under your name (and Co-authored-by: by me) together with a
slightly amended test code.
--
Reply to this email directly or view it on GitLab:
https://gitlab.com/gnuwget/wget2/-/merge_requests/505#note_1005679321
You're receiving this email because of your account on gitlab.com.
- Re: wget2 | Draft: Small fixes (!505), (continued)
- Re: wget2 | Draft: Small fixes (!505), Avinash Sonawane (@rootkea), 2022/06/23
- Re: wget2 | Draft: Small fixes (!505), @rockdaboot, 2022/06/25
- Re: wget2 | Draft: Small fixes (!505), Avinash Sonawane (@rootkea), 2022/06/25
- Re: wget2 | Draft: Small fixes (!505), @rockdaboot, 2022/06/25
- Re: wget2 | Draft: Small fixes (!505), @rockdaboot, 2022/06/25
- Re: wget2 | Draft: Small fixes (!505), @rockdaboot, 2022/06/25
- Re: wget2 | Draft: Small fixes (!505),
@rockdaboot <=
- Re: wget2 | Draft: Small fixes (!505), @rockdaboot, 2022/06/26