Hi Michael,

Thanks for the patch and the excellent explanation. It makes total sense - I 
applied the patch.

Best regards,
        Dom

Am Freitag 11 Juni 2010 schrieben Sie:
> 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 );
> 


-- 
**********************************************************************
Dominik Seichter - [email protected]
KRename  - http://www.krename.net  - Powerful batch renamer for KDE
KBarcode - http://www.kbarcode.net - Barcode and label printing
PoDoFo - http://podofo.sf.net - PDF generation and parsing library
SchafKopf - http://schafkopf.berlios.de - Schafkopf, a card game,  for KDE
Alan - http://alan.sf.net - A Turing Machine in Java
**********************************************************************

Attachment: signature.asc
Description: This is a digitally signed message part.

------------------------------------------------------------------------------
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