support empty strings
This commit is contained in:
parent
142e478c51
commit
44d68e19d7
1 changed files with 6 additions and 4 deletions
|
@ -730,14 +730,16 @@ ne_read_string(nestegg * ctx, char ** val, uint64_t length)
|
||||||
char * str;
|
char * str;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (length == 0 || length > LIMIT_STRING)
|
if (length > LIMIT_STRING)
|
||||||
return -1;
|
return -1;
|
||||||
str = ne_pool_alloc(length + 1, ctx->alloc_pool);
|
str = ne_pool_alloc(length + 1, ctx->alloc_pool);
|
||||||
if (!str)
|
if (!str)
|
||||||
return -1;
|
return -1;
|
||||||
|
if (length) {
|
||||||
r = ne_io_read(ctx->io, (unsigned char *) str, length);
|
r = ne_io_read(ctx->io, (unsigned char *) str, length);
|
||||||
if (r != 1)
|
if (r != 1)
|
||||||
return r;
|
return r;
|
||||||
|
}
|
||||||
str[length] = '\0';
|
str[length] = '\0';
|
||||||
*val = str;
|
*val = str;
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in a new issue