Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复了mingw下的显示异常的问题
由于
linux和windows下snprintf返回值不同根据输出结果总结如下:
在
windows下, 如果字符串长度大于count, 函数返回-1以标志可能导致的错误, 如果字符串长度小于或者等于count, 函数返回实际的字符串的长度. 在linux下, 返回实际的字符串的长度.输出不同, 在
windows下, 如果字符串长度大于count, 会输出count个字符, 但是没有结束符, 后面的值会混乱; 如果字符串的长度等于count, 输出全部字符串, 但是没有结束符, 后面的值同样很混乱; 在linux下, 永远输出count - 1个字符, 加一个结束符 '\0', 所以在本例子中,count = 13时, 无论windows下还是linux下都正确.因此修改代码中,
snprintf后, 增加 buf[XXX] = '\0';