Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bstring/bstrlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ blk2bstr(const void *blk, int len)
{
bstring b;
int i;
if (blk == NULL || len < 0) {
if (len < 0 || (len > 0 && blk == NULL)) {
return NULL;
}
b = malloc(sizeof(struct tagbstring));
Expand Down
3 changes: 3 additions & 0 deletions bstring/bstrlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ bfromcstrrangealloc(int minl, int maxl, const char *str);
* Create a bstring whose contents are described by the contiguous buffer
* pointing to by blk with a length of len bytes.
*
* If len is zero, blk may be NULL. Otherwise, blk must point to at least len
* bytes.
*
* Note that this function creates a copy of the data in blk, rather than
* simply referencing it. Compare with the blk2tbstr macro. If an error
* occurs NULL is returned.
Expand Down
2 changes: 1 addition & 1 deletion tests/bstest.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ START_TEST(core_001)
{
/* tests with NULL */
test1_0(NULL, 10, NULL);
test1_0(NULL, 0, NULL);
test1_0(NULL, 0, "");
test1_0(NULL, -1, NULL);
/* normal operation tests */
test1_0(SHORT_STRING, sizeof(SHORT_STRING) - 1, SHORT_STRING);
Expand Down
Loading