support empty strings

This commit is contained in:
j 2014-07-19 16:24:01 +02:00
parent 142e478c51
commit 44d68e19d7

View file

@ -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;