On 18/04/12 01:08, Stephen Kitt wrote:
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.
I agree with the two points above!
I'll track upstream bug, thank you very much!
--
Eugen
--
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org