[07_answer] lept_stringify_value 函数中的case number优化导致程序卡住
static void lept_stringify_value(lept_context* c, const lept_value* v) { case LEPT_NUMBER: c->top -= 32 - sprintf(lept_context_push(c, 32), "%.17g", v->u.n); break;
这一句不能优化,因为c->top = 0; c->top -= 32 - sprintf()在这个情况下等价于 c->top = 0 - (32 - sprintf()) 导致计算的c->top可能出现负值。程序就会出问题。 本质原因是lept_context_push函数里,会让c->top发生变化。
这个问题具体怎么回事,和编译器有很大关系。
我总结的结果就是:在使用+= 或者 -=时,一定要确保右边的代码不能改动左边的变量,否则会出现意想不到的错误。
我的也一直卡着
我是这句,错误 LNK2019 无法解析的外部符号 sprintf,该符号在函数 lept_stringify_value 中被引用,这该咋搞,我是vs2015
我是这句,错误 LNK2019 无法解析的外部符号 sprintf,该符号在函数 lept_stringify_value 中被引用,这该咋搞,我是vs2015
无法解析应该是因为没有include头文件<stdio.h>。
我也是这一行代码卡着,请问大家解决了吗?这边报错是: error C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.但是我改用了sprintf_s后说我缺少参数,但是我是按照sprintf_s的形参列表调用的呀
我也出现这个问题,debug了好久。 每次单步调试就正常,但是如果使用 next 跳过 lept_stringify_value 函数,再看c.top的值是 18446744073709551585,然后就卡死了。