分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

skynet的timer似乎有问题

发布时间:2023-09-06 02:22责任编辑:赖小花关键词:暂无标签

skynet.timeout 传进去 number 范围内的数值但是会溢出,
调查发现 skynet.timeout 调用的是 c 的方法:

c.intcommand("TIMEOUT",ti)

对应的C方法中会把传入的 number 转换成 int32:

static intlintcommand(lua_State *L) { ???struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1)); ???const char * cmd = luaL_checkstring(L,1); ???const char * result; ???const char * parm = NULL; ???char tmp[64]; ??// for integer parm ???if (lua_gettop(L) == 2) { ???????if (lua_isnumber(L, 2)) { ???????????int32_t n = (int32_t)luaL_checkinteger(L,2); ???????????sprintf(tmp, "%d", n); ???????????parm = tmp; ???????} else { ???????????parm = luaL_checkstring(L,2); ???????} ???} ???result = skynet_command(context, cmd, parm); ???if (result) { ???????char *endptr = NULL; ????????lua_Integer r = strtoll(result, &endptr, 0); ???????if (endptr == NULL || *endptr != '\0') { ???????????// may be real number ???????????double n = strtod(result, &endptr); ???????????if (endptr == NULL || *endptr != '\0') { ???????????????return luaL_error(L, "Invalid result %s", result); ???????????} else { ???????????????lua_pushnumber(L, n); ???????????} ???????} else { ???????????lua_pushinteger(L, r); ???????} ???????return 1; ???} ???return 0;}

所以传入数字不再 2^31 ~ -2^31 的值都将会溢出,然后就导致bug产生。

skynet的timer似乎有问题

原文地址:https://www.cnblogs.com/adoontheway/p/9974528.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved