Skip to content

tb_vsnprintf当第二个参数即缓冲区大小为0时,行为与标准库中的vsnprintf不一致 #276

Open
@duyanning

Description

@duyanning

描述问题

tbox目前的实现是这样的

tb_long_t tb_vsnprintf(tb_char_t* s, tb_size_t n, tb_char_t const* fmt, tb_va_list_t args)
{
    // check
    if (!n || !s || !fmt) return 0;

即当n等于0时,直接返回0。

期待的结果

然而标准库里的vsnprintf的行为是这样的:
If bufsz is zero, nothing is written and buffer may be a null pointer, however the return value (number of bytes that would be written not including the null terminator) is still calculated and returned.

参考:https://en.cppreference.com/w/c/io/vfprintf

错误信息

如果可能,请尽量附加程序运行过程中的错误输出信息。

相关环境

请提供编译和运行环境信息。

其他信息

请提供其他附加信息帮助我们诊断问题。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions