]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
dynbuf: return NULL when there's no buffer length
authorDaniel Stenberg <daniel@haxx.se>
Sun, 17 May 2020 17:47:45 +0000 (19:47 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Sun, 17 May 2020 21:20:56 +0000 (23:20 +0200)
... 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 ed35d6590e72c
Closes #5405

docs/DYNBUF.md
lib/dynbuf.c

index 3ab059bae1baafa969c7f8df86ea05ad08f9c3ae..550477ee1e6ea21f624643737d0722736545375c 100644 (file)
@@ -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
 
index 64004952fe1bb9407ddec8a2757c1d01aef09d5f..dfc1d05c6426ef2db3f41203bc012275a139c198 100644 (file)
@@ -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;
 }
 
 /*
@@ -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;
 }
 
 /*