On Wed, 29 Nov 2023, LIU Hao wrote:

在 2023/11/29 18:38, Antonin Décimo 写道:
Previous code was too complex and hard to understand, and snprintf
fits the job nicely.

Signed-off-by: Antonin Décimo <[email protected]>
---
mingw-w64-libraries/winpthreads/src/thread.c | 21 ++++----------------
  1 file changed, 4 insertions(+), 17 deletions(-)


+      char threaderr[sizeof(THREADERR) + 8] = { 0 };
+ snprintf(threaderr, sizeof(threaderr), THREADERR, GetCurrentThreadId());


I think `sprintf()` should be called here, as the length of the output string has an upper limit.

Even for bounded output sizes, it may make sense to avoid sprintf - many environments warn on any use of it, even if the buffer can be guaranteed to be large enough. Although I'm not sure if any of our tools warn about it.

There wasn't `snprintf()` in MSVCRT.DLL from Windows XP.

Actually, no msvcrt.dll on any system has got the snprintf function.

In msvcrt builds (without our ansi stdio support enabled), when calling snprintf, it calls our internal __ms_snprintf.

This function is implemented with _vscprintf. This function exists in msvcrt.dll since XP, but is absent on 2k and earlier. However dd72602ea5ed0e612d9825ede518970ed810dbb7 added a fallback implementation, making our snprintf safe to use for any target.

// Martin

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to