Skip to content

CRT::StringPrint && CRT::StringPrintN should using stb_sprintf #237

@maecry

Description

@maecry

inline Q_CRT_FORMAT_STRING_ATTRIBUTE(printf, 2, 3) int StringPrint(char* szBuffer, const char* const szFormat, ...)

        inline Q_CRT_FORMAT_STRING_ATTRIBUTE(printf, 2, 3) int StringPrint(char* szBuffer, const char* const szFormat, ...)
	{
		va_list args;
		va_start(args, szFormat);

		const int iReturn = stbsp_vsprintf(szBuffer, szFormat, args);

		va_end(args);

		return iReturn;
	}

inline Q_CRT_FORMAT_STRING_ATTRIBUTE(printf, 3, 4) int StringPrintN(char* szBuffer, std::size_t nCount, const char* const szFormat, ...)

	Q_INLINE Q_CRT_FORMAT_STRING_ATTRIBUTE(printf, 3, 4) int StringPrintN(char* szBuffer, std::size_t nCount, const char* const szFormat, ...)
	{
	        // @note: same as https://github.com/rollraw/qo0-csgo/blob/c477e85116d43a534dcb8e887c48091ae4146514/dependencies/imgui/imgui.cpp#L1373
		va_list args;
		va_start(args, szFormat);

		const int iReturn = stbsp_vsnprintf(szBuffer, static_cast<int>(nCount), szFormat, args);

		va_end(args);

		if (szBuffer == nullptr)
                    return iReturn ;
                if (iReturn  == -1 || w >= (int)nCount)
                    iReturn  = (int)nCount - 1;
                szBuffer[iReturn] = 0;
                
		return iReturn;
	}

or we should add a configuration in user.h as Q_USE_USE_STB_SPRINTF since we don't really need to sig scan this, such as waste as we already using stb_sprintf

note: There might be typos cuz yes I typed on github

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions