Re: basic_string causes crash in _vsnprintf???
- From: WXS <WXS@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 24 Jun 2005 06:01:04 -0700
Thanks for the help. Also a quick read of pclint's warnings seems to suggest
it will detect situations like this, so I plan to get a copye and give it a
try, as I think we have a lot of other methods other than printf being called.
"Hendrik Schober" wrote:
> WXS <WXS@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> > [...]
> > I was wondering if anyone knows if a PCLint like product will detect this
> > issue we could use on our code base?
>
> I don't, but it seems that if you replace
> 'printf()' with some overloaded functions
> template and compile with that, you would
> be able to have compiler errors generated.
> Um, off the top of my head...
>
> // beware, uncimpiled code ahead
> int printf(const char*)
>
>
> template< typename T1 >
> int printf(const char*, T1)
> {
> testForStr<T1>();
> }
>
>
> template< typename T1, typename T2 >
> int printf(const char*, T1, T2)
> {
> testForStr<T1>();
> testForStr<T2>();
> }
>
>
> template< typename T1, typename T2, typename T3 >
> int printf(const char*, T1, T2, T3)
> {
> testForStr<T1>();
> testForStr<T2>();
> testForStr<T3>();
> }
>
> //...
>
> Now you need this test to generate an
> error if the template argument is an
> instance of 'std::basic_string<>':
>
> // beware, uncimpiled code ahead
> template< typename T >
> struct Tester {
> typedef int test;
> };
>
> template< typename TCh, typename TTr, typename TAl >
> struct Tester< std::basic_string<TCh,TTr,TAl> > {
> typedef typename
> std::basic_string<TCh,TTr,TAl>::compile_time_error test;
> };
>
> template< typename T >
> void testForStr()
> {
> typedef typename Tester<T>::test test;
> }
>
> I haven't tested this, but it should give you
> an idea of what I'm getting at.
> If, on one machine, you replace the definition
> of 'printf()' with this and then try to compile
> the code, you should get an error for every
> string you pass to any 'printf()' because that
> 'compile_time_error' isn't a member of any
> 'std::basic_string<>' instance.
> (Wait, 'printf()' is for 'char' only, so you
> would only need 'std::string', right? Well,
> so it's even simpler than that...)
>
> > Thanks,
>
> HTH!
>
> > Dave
> > [...]
>
> Schobi
>
> --
> SpamTrap@xxxxxx is never read
> I'm Schobi at suespammers dot org
>
> "Coming back to where you started is not the same as never leaving"
> Terry Pratchett
>
>
>
.
- Follow-Ups:
- Re: basic_string causes crash in _vsnprintf???
- From: Hendrik Schober
- Re: basic_string causes crash in _vsnprintf???
- References:
- basic_string causes crash in _vsnprintf???
- From: WXS
- RE: basic_string causes crash in _vsnprintf???
- From: WXS
- Re: basic_string causes crash in _vsnprintf???
- From: Hendrik Schober
- basic_string causes crash in _vsnprintf???
- Prev by Date: Re: basic_string causes crash in _vsnprintf???
- Next by Date: Re: basic_string causes crash in _vsnprintf???
- Previous by thread: Re: basic_string causes crash in _vsnprintf???
- Next by thread: Re: basic_string causes crash in _vsnprintf???
- Index(es):
Relevant Pages
|
|