New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer) #492
Comments
Hi @mengxiangren , function |
Thanks for your reply, please see example.c
…------------------ 原始邮件 ------------------
发件人: "DaveGamble/cJSON" <notifications@github.com>;
发送时间: 2020年8月5日(星期三) 上午10:08
收件人: "DaveGamble/cJSON"<cJSON@noreply.github.com>;
抄送: "孟乡人"<775924562@qq.com>;"Mention"<mention@noreply.github.com>;
主题: Re: [DaveGamble/cJSON] static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer) (#492)
Hi @mengxiangren , function print_value and struct printbuffer is not exposed to users, and the memory allocation of the print_buffer is performed inside the static function. Where do you find that the output_buffer->buffer becomes global?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Explame one: static buf[100]; cJSON_PrintPreallocated(root, buf, 100, 1) Explame two: static struct fa{ flexible_array = molloc(sizeof(struct fa) + 100); cJSON_PrintPreallocated(root, flexible_array->buf, 100, 1) printf("%s", flexible_array->buf);//if reallocte buf, it is error |
then the |
I suggest you test it in your server and post the error logs, in case I mishandle something. |
I means, the buf(static) shouldn't reallocate, becase the buf is global |
if static buf[100], the realloc(50), it is right |
|
sorry,it should |
struct fa is contiguous memory address, if reallocate fa.buf, then struct fa will not contiguous memory address |
Lines 1286 to 1303 in cf97c6f
if the length of buffer is smaller than needed , then it will return NULL in line464.Lines 434 to 465 in cf97c6f
|
|
I have another question, in print_value() static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer) |
The print_value() very absurd!!!
eg:
(1) if output_buffer->buffer is global, the function is very danger!!!
(2) struct{
int flag;
char buf[];
}
if output_buffer->buffer point to buf[] and buf[] realloced, oh mg god!!!
The text was updated successfully, but these errors were encountered: