> Modified: podofo/trunk/tools/podofoimpose/pdftranslator.cpp
> ===================================================================
> --- podofo/trunk/tools/podofoimpose/pdftranslator.cpp 2007-09-19 15:19:00 UTC
> (rev 649)
> +++ podofo/trunk/tools/podofoimpose/pdftranslator.cpp 2007-09-20 15:48:24 UTC
> (rev 650)
> @@ -85,10 +85,62 @@
>
> void PdfTranslator::setSource ( const std::string & source )
> {
> - inFilePath = source;
> - sourceDoc = new PdfMemDocument ( inFilePath.c_str() ); // must succeed
> or throw
> + ifstream in ( source.c_str(), ifstream::in );
> + if (!in.good())
> + throw runtime_error("setSource() failed to open input file");
> +
> + char *magicBuffer = new char [5];
> + in.read(magicBuffer, 5);
> + std::string magic( magicBuffer , 5 );
This is a memory leak, as magicBuffer is never freed. It's not a big
issue but should be fixed. Eliminating the dynamic memory allocation in
favour of a stack-based static buffer would be preferable - overrun is
not a risk since read() checks length limits.
eg:
const int magicBufferLen = 5;
char magicBuffer[magicBufferLen ];
in.read(magicBuffer, magicBufferLen );
std::string magic( magicBuffer , magicBufferLen );
(on a side note, I've always disliked how the iostreams library doesn't
interact properly with the STL re strings etc. Qt is a _lot_ nicer in
this regard, and it's a real pity they don't seem to want to address it
for C++0x. The above code is just ugly, but the Qt version is nice. They
also don't seem to be adding core functionality like a standard Unicode
string class that's _useful_ (works properly in iostreams; does encoding
conversions; knows its own encoding, etc) like QString does. It makes
one wonder about the language's future as an app-level rather than
system-level tool).
--
Craig Ringer
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Podofo-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/podofo-users