Re: "NUL" device is missing
From: Chuck Chopp (ChuckChopp_at_rtfmcsi.com)
Date: 05/14/04
- Next message: Slobodan Brcin \(eMVP\): "Re: XP Embedded licensing"
- Previous message: Chris: "XP Embedded licensing"
- In reply to: KM: "Re: "NUL" device is missing"
- Next in thread: KM: "Re: "NUL" device is missing"
- Reply: KM: "Re: "NUL" device is missing"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 14 May 2004 07:16:22 -0400
KM wrote:
> What VC version you are building against?
> The reason I am asking is that the issue has been fixed in C standard of 99
> year. Only VC 2003 has peaked up the fix.
> The fix was to pass NULL to _snprintf to count the number of characters
> required for a specified formating string. Basically, you can make a call
> like: _snprintf(NULL,0,"%...",...) and it will return you the number.
>
> You can easy track this down exploring CRT source of VC. In VC 6.0
> (sprintf.h, output.c, stdio.h) you may see that the string formating routine
> subcalls do not check for NULL. In VC 2003 CRT, they do (output.c, write_xxx
> functions called from _output). This may be a cure for you. Also, there is
> another useful wrapper (don't know if it is ANSI compatible) -
> _scprintf(char* format,...) - this will return the same number of characters
> you need.
I'm stuck using Visual C/C++ v6.0 right now w/o the option to move on up to
the Studio 2003 compiler. However, I will keep this in mind for future use.
I spent quite a bit of time last night reviewing the source code for the
CRT and had reached the point where everything comes down to a call to the
_output() function that does all of the dirty work. If it is one of the
string printf() types of functions, then a dummy _iob [a.k.a. "FILE"
structure] is worked up where it lookes like a valid file handle but really
points to the string buffer. I can see the counted vs. uncounted versions
set a member in the structure to limit define the output buffer size.
Still, it is the _output() function that does all of the work and I haven't
gone through and reviewe the source code for _output to see if it tests
properly for NULL. I think that in VC6 it doesnn't as I've had errors occur
when passing in a NULL pointer to sprintf(). I'll look at it all in more
detail today.
It is encouraging to hear than an updated ANSI C standard does finally
address this problem, though. I've got VS2003 .NET on hand and I will
review the CRT source code from it, too, to see what the differences in the
implementation look like. Perhaps I can cook up my own flavor of _output()
to use with VC6 in my own code to back-port that functionality and thus
remove the dependency on the NUL device.
-- Chuck Chopp ChuckChopp (at) rtfmcsi (dot) com http://www.rtfmcsi.com RTFM Consulting Services Inc. 864 801 2795 voice & voicemail 103 Autumn Hill Road 864 801 2774 fax Greer, SC 29651 Do not send me unsolicited commercial email.
- Next message: Slobodan Brcin \(eMVP\): "Re: XP Embedded licensing"
- Previous message: Chris: "XP Embedded licensing"
- In reply to: KM: "Re: "NUL" device is missing"
- Next in thread: KM: "Re: "NUL" device is missing"
- Reply: KM: "Re: "NUL" device is missing"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|