sajson icon indicating copy to clipboard operation
sajson copied to clipboard

Confusing size description of passed buffer

Open lundmark opened this issue 4 years ago • 2 comments

So we've had some problems with this: https://github.com/chadaustin/sajson/blob/eeaa7ee736ec2f826c7a30c0e340e5331d8efc57/include/sajson.h#L1115

It says "size_in_words" which is a very unusual way to describe the size of a buffer. I'd say it's very not standard. Would it be possible to update this?

lundmark avatar Feb 09 '21 11:02 lundmark

Hi @lundmark. Agreed it's a bit unusual to use sizeof(size_t) as the allocation granularity for the AST, but that's how the AST is stored. If you have a size in bytes, you can just pass size_in_bytes / sizeof(size_t).

Would a doc comment help?

chadaustin avatar Feb 09 '21 20:02 chadaustin

Hi,

I think that it should accept a char *buffer and a size_t size_in_bytes instead.

I've never before seen an allocation api accept a size_t * and a size that is array_length as parameter (which would have been a less confusing name). Buffers are best described as memory chunks + number of bytes, which is different from arrays + length.

lundmark avatar Feb 10 '21 07:02 lundmark