Skip to content

Commit

Permalink
dynbuf: return NULL when there's no buffer length
Browse files Browse the repository at this point in the history
... as returning a "" is not a good idea as the string is supposed to be
allocated and returning a const string will cause issues.

Reported-by: Brian Carpenter
Follow-up to ed35d65
Closes #5405
  • Loading branch information
bagder committed May 17, 2020
1 parent 2c598cc commit 3df42ca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions docs/DYNBUF.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ larger than the buffer length.

char *Curl_dyn_ptr(const struct dynbuf *s);

Returns a `char *` to the buffer. Since the buffer may be reallocated, this
pointer should not be trusted or used anymore after the next buffer
manipulation call.
Returns a `char *` to the buffer if it has a length, otherwise a NULL. Since
the buffer may be reallocated, this pointer should not be trusted or used
anymore after the next buffer manipulation call.

## uptr

unsigned char *Curl_dyn_uptr(const struct dynbuf *s);

Returns an `unsigned char *` to the buffer. Since the buffer may be
reallocated, this pointer should not be trusted or used anymore after the next
buffer manipulation call.
Returns an `unsigned char *` to the buffer if it has a length, otherwise a
NULL. Since the buffer may be reallocated, this pointer should not be trusted
or used anymore after the next buffer manipulation call.

## len

Expand Down
4 changes: 2 additions & 2 deletions lib/dynbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ char *Curl_dyn_ptr(const struct dynbuf *s)
DEBUGASSERT(s);
DEBUGASSERT(s->init == DYNINIT);
DEBUGASSERT(!s->leng || s->bufr);
return s->leng ? s->bufr : (char *)"";
return s->bufr;
}

/*
Expand All @@ -212,7 +212,7 @@ unsigned char *Curl_dyn_uptr(const struct dynbuf *s)
DEBUGASSERT(s);
DEBUGASSERT(s->init == DYNINIT);
DEBUGASSERT(!s->leng || s->bufr);
return s->leng ? (unsigned char *)s->bufr : (unsigned char *)"";
return (unsigned char *)s->bufr;
}

/*
Expand Down

0 comments on commit 3df42ca

Please sign in to comment.