liudf0716 / xfrpc

The xfrpc project is a lightweight implementation of the FRP client written in C language for OpenWRT and IoT systems. It is designed to provide an efficient solution for resource-constrained devices such as OpenWRT routers and IoT devices, which often have limited ROM and RAM space.
GNU General Public License v3.0
724 stars 92 forks source link

A 32bit cpu incompatibility problem about timestamp. #52

Closed mumianbaba closed 1 year ago

mumianbaba commented 1 year ago
struct login {
    char        *version;
    char        *hostname;
    char        *os;
    char        *arch;
    char        *user;
    char        *privilege_key;
    long int    timestamp;
    char        *run_id;
    char        *metas;
    int         pool_count;

    /* fields not need json marshal */
    int         logged;     //0 not login 1:logged
};

在login.h文件中的结构体login 中的timestamp成员定义为long int类型,在32位架构CPU中,该类型为4 bytes。在msg.c文件的login_request_marshal函数中调用JSON_MARSHAL_TYPE(j_login_req, "timestamp", int64, lg->timestamp);。int64类型是8 bytes。存在兼容性问题。 建议使用time_t类型,然后根据sizeof(time_t)来选择传入的是int64还是int。cJOSN就做的很好,直接使用double存所有的数字。

liudf0716 commented 1 year ago

谢谢详细的分析!