Hi Eugen,

On Tue, Apr 17, 2012 at 04:36:37PM +0200, Eugen Dedu wrote:
> Suppose the following program (b.cpp):
> //#include <dshow.h>
> 
> //#undef sprintf
> //#define sprintf sprintf_instead_use_StringCbPrintfA_or_StringCchPrintfA;
> 
> class PString
> {
> public:
>   PString & sprintf(const char * cfmt, ...);
> };
> 
> PString & PString::sprintf(const char * fmt, ...)
> {
>   return *this;
> }
> 
> int main (void)
> {
>   PString x;
>   x.sprintf ("%d", 0);
>   return 0;
> }
> 
> When compiling it with "i686-w64-mingw32-g++ b.cpp" there is no error.
> 
> Uncommenting either the first line, or the 3rd and 4th lines, and
> recompiling leads to an error:
> $ i686-w64-mingw32-g++ b.cpp
> b.cpp:9:21: error: expected unqualified-id before ‘const’
> b.cpp:9:21: error: expected ‘)’ before ‘const’
> b.cpp:12:20: error: ‘PString& 
> PString::sprintf_instead_use_StringCbPrintfA_or_StringCchPrintfA’ is not a 
> static member of ‘class PString’
> [...]
> 
> The problem is that dshow.h includes strsafe.h, which contains:
> #undef sprintf
> #define sprintf sprintf_instead_use_StringCbPrintfA_or_StringCchPrintfA;
> hence the error about not finding sprintf_instead_...

>From a purely syntactic point of view the problem is the semi-colon
(';') at the end of the #define - removing it (either in the header
file or in b.cpp) allows b.cpp to build again.

> There are two bugs here:
> 
> 1. Preventing use of the dangerous sprintf by using #define ... seems
> not a good idea, since it prevents correct programs like the above to
> compile.  Maybe they chose a simple solution which does not work on
> the 0.1% of programs which use a method called "sprintf"?

Indeed... I gather that the idea is to cause compile-time errors on
code using "unsafe" methods, but the approach does have unfortunate
side-effects.

> 2. The above #define sprintf... is put in strsafe.h, which is included
> ONLY by dhow.h.  Shouldn't it be included by string.h or another much more
> general header?!  In fact, "grep -r strsafe /usr/i686-w64-mingw32/include/"
> shows:
> /usr/i686-w64-mingw32/include/tchar.h:#error Need to include strsafe.h after 
> tchar.h
> /usr/i686-w64-mingw32/include/dshow.h:#include <strsafe.h>
> /usr/i686-w64-mingw32/include/ddk/ntstrsafe.h: * FILE:            
> include/ddk/ntstrsafe.h

I have no idea... I'll ask upstream!

Regards,

Stephen



--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to