Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Is Sscanf() OK?

May
12,798
160
I have a plugin that begins like this.
Code:
INT WINAPI TEST ( LPWSTR psz )
{
    WCHAR c;
    INT n = Sscanf(psz, L" %c", &c);
    Printf(L"n = %d ... **%c** ... %d\r\n", n, c, c);

If I call that plugin with no arguments, Sscanf returns 1. I imagine the value of c is whatever garbage was there in the first place. But should Sscanf() return 1?
Code:
v:\> test
n = 1 ... **䝨** ... 18280

v:\> test
n = 1 ... **睸** ... 30584

v:\> test
n = 1 ... **枈** ... 26504
 
First, I don't recommend that you use Sscanf, Sprintf, or Printf. They were necessary a few years ago when the RTL was missing some critical things (like support for 64-bit ints), and they were faster than the MS implementations. They are no longer necessary, and I'll be eliminating them in another (major) version or two.

Second, TCC never passes empty or invalid arguments to Sscanf, so it doesn't check for null / empty string arguments. Adding that would mean unnecessary overhead.
 
First, I don't recommend that you use Sscanf, Sprintf, or Printf. They were necessary a few years ago when the RTL was missing some critical things (like support for 64-bit ints), and they were faster than the MS implementations. They are no longer necessary, and I'll be eliminating them in another (major) version or two.

Second, TCC never passes empty or invalid arguments to Sscanf, so it doesn't check for null / empty string arguments. Adding that would mean unnecessary overhead.
Thanks for the reply. I build my plugins with /MT so all the C stuff gets built in. Avoiding wprintf and swscanf keeps them small. Does the same go for Qprintf (vs. fwprintf)?
 
First, I don't recommend that you use Sscanf, Sprintf, or Printf. They were necessary a few years ago when the RTL was missing some critical things (like support for 64-bit ints), and they were faster than the MS implementations. They are no longer necessary, and I'll be eliminating them in another (major) version or two.

Oh, please don't eliminate Printf. I use it all the time, as it handles redirection correctly, unlike the RTL functions. (The other two I don't care about.)
 
Oh, please don't eliminate Printf. I use it all the time, as it handles redirection correctly, unlike the RTL functions. (The other two I don't care about.)
I'll second that! With Printf (probably Qprintf also) redirection and piping of plugin output happen seamlessly with no effort on the part of the plugin author. And they don't happen at all with wprintf (and probably fwprintf). If there's some monkeying with streams and standard handles that will let the C library output functions work as the SDK ones, please tell me how to do that.
 
Likewise QPuts() and CrLf(), little functions that do nothing fancy, but do it right.
 
Back
Top