Hey guys

I think I have found a bug with PdfString::SetHexData()

when determining if a Hex-encoded string is Unicode, we test the first couple of bytes, however on windows this test always fails:

#ifdef _MSC_VER    // MSC warns of possible truncation for static_cast
m_bUnicode = (m_buffer.GetBuffer()[0] == 0xFE && m_buffer.GetBuffer()[1] == 0xFF);

The above comparison will always fail since we're comparing a signed char vs an unsigned char. Even if m_buffer[0]= 0xfe and m_buffer[1]==0xff, the comparison is going to resolve to something like (-2 == 254 && -1 ==255) I think that all that needs to be done here is cast the hex value to a char and we're good to go:

m_bUnicode = (m_buffer.GetBuffer()[0] == static_cast<char>(0xFE) && m_buffer.GetBuffer()[1] == static_cast<char>(0xFF));

Which is what the non-windows version is doing already. The comment for MSC_VER mentions that this was done to silence a truncation warning, which I don't see when I compile using studio '05.

I would recommend that the windows-specific line is removed, patch follows.

Cheers!
~Michael Marsella


Index: PdfString.cpp
===================================================================
--- PdfString.cpp    (revision 31384)
+++ PdfString.cpp    (working copy)
@@ -292,11 +292,8 @@
// Now check for the first two bytes, to see if we got a unicode string
     if( m_buffer.GetSize()-2 > 2 )
     {
-#ifdef _MSC_VER    // MSC warns of possible truncation for static_cast
- m_bUnicode = (m_buffer.GetBuffer()[0] == 0xFE && m_buffer.GetBuffer()[1] == 0xFF);
-#else
m_bUnicode = (m_buffer.GetBuffer()[0] == static_cast<char>(0xFE) && m_buffer.GetBuffer()[1] == static_cast<char>(0xFF));
-#endif
+
         if( m_bUnicode )
         {
             PdfRefCountedBuffer temp( m_buffer.GetSize() - 2 );


Index: PdfString.cpp
===================================================================
--- PdfString.cpp       (revision 31384)
+++ PdfString.cpp       (working copy)
@@ -292,11 +292,8 @@
     // Now check for the first two bytes, to see if we got a unicode string
     if( m_buffer.GetSize()-2 > 2 ) 
     {
-#ifdef _MSC_VER        // MSC warns of possible truncation for static_cast
-               m_bUnicode = (m_buffer.GetBuffer()[0] == 0xFE && 
m_buffer.GetBuffer()[1] == 0xFF);
-#else
                m_bUnicode = (m_buffer.GetBuffer()[0] == 
static_cast<char>(0xFE) && m_buffer.GetBuffer()[1] == static_cast<char>(0xFF));
-#endif
+               
                if( m_bUnicode ) 
         {
             PdfRefCountedBuffer temp( m_buffer.GetSize() - 2 );
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Podofo-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to