Permalink
Browse files

Avoid using Resource::data as string, as it is not null terminated.

  • Loading branch information...
Dimitri van Heesch
Dimitri van Heesch committed Aug 31, 2015
1 parent a5bb943 commit 15a87a623791bf407b3076960cdd1133c8973357
Showing with 30 additions and 45 deletions.
  1. +18 −30 src/htmlgen.cpp
  2. +3 −3 src/resourcemgr.h
  3. +9 −12 src/template.cpp
View
@@ -732,25 +732,17 @@ void HtmlGenerator::init()
QFile f(dname+"/dynsections.js");
if (f.open(IO_WriteOnly))
{
const Resource *res = mgr.get("dynsections.js");
if (res)
{
FTextStream t(&f);
t << (const char *)res->data;
if (Config_getBool("SOURCE_BROWSER") && Config_getBool("SOURCE_TOOLTIPS"))
{
t << endl <<
"$(document).ready(function() {\n"
" $('.code,.codeRef').each(function() {\n"
" $(this).data('powertip',$('#'+$(this).attr('href').replace(/.*\\//,'').replace(/[^a-z_A-Z0-9]/g,'_')).html());\n"
" $(this).powerTip({ placement: 's', smartPlacement: true, mouseOnToPopup: true });\n"
" });\n"
"});\n";
}
}
else
FTextStream t(&f);
t << mgr.getAsString("dynsections.js");
if (Config_getBool("SOURCE_BROWSER") && Config_getBool("SOURCE_TOOLTIPS"))
{
err("Resource dynsections.js not compiled in");
t << endl <<
"$(document).ready(function() {\n"
" $('.code,.codeRef').each(function() {\n"
" $(this).data('powertip',$('#'+$(this).attr('href').replace(/.*\\//,'').replace(/[^a-z_A-Z0-9]/g,'_')).html());\n"
" $(this).powerTip({ placement: 's', smartPlacement: true, mouseOnToPopup: true });\n"
" });\n"
"});\n";
}
}
}
@@ -815,20 +807,16 @@ void HtmlGenerator::writeSearchData(const char *dir)
QFile f(searchDirName+"/search.css");
if (f.open(IO_WriteOnly))
{
const Resource *res = mgr.get("search.css");
if (res)
FTextStream t(&f);
QCString searchCss = replaceColorMarkers(mgr.getAsString("search.css"));
searchCss = substitute(searchCss,"$doxygenversion",versionString);
if (Config_getBool("DISABLE_INDEX"))
{
FTextStream t(&f);
QCString searchCss = replaceColorMarkers((const char *)res->data);
searchCss = substitute(searchCss,"$doxygenversion",versionString);
if (Config_getBool("DISABLE_INDEX"))
{
// move up the search box if there are no tabs
searchCss = substitute(searchCss,"margin-top: 8px;","margin-top: 0px;");
}
t << searchCss;
Doxygen::indexList->addStyleSheetFile("search/search.css");
// move up the search box if there are no tabs
searchCss = substitute(searchCss,"margin-top: 8px;","margin-top: 0px;");
}
t << searchCss;
Doxygen::indexList->addStyleSheetFile("search/search.css");
}
}
View
@@ -47,13 +47,13 @@ class ResourceMgr
/** Copies a registered resource to a given target directory under a given target name */
bool copyResourceAs(const char *name,const char *targetDir,const char *targetName) const;
/** Returns a pointer to the resource object with the given name. */
const Resource *get(const char *name) const;
/** Gets the resource data as a C string */
QCString getAsString(const char *name) const;
private:
/** Returns a pointer to the resource object with the given name. */
const Resource *get(const char *name) const;
ResourceMgr();
~ResourceMgr();
class Private;
View
@@ -2410,7 +2410,7 @@ class TemplateNodeList : public QList<TemplateNode>
class TemplateImpl : public TemplateNode, public Template
{
public:
TemplateImpl(TemplateEngine *e,const QCString &name,const char *data,int size,
TemplateImpl(TemplateEngine *e,const QCString &name,const QCString &data,
const QCString &extension);
void render(FTextStream &ts, TemplateContext *c);
@@ -4537,7 +4537,7 @@ void TemplateBlockContext::push(TemplateNodeBlock *block)
class TemplateLexer
{
public:
TemplateLexer(const TemplateEngine *engine,const QCString &fileName,const char *data,int size);
TemplateLexer(const TemplateEngine *engine,const QCString &fileName,const QCString &data);
void tokenize(QList<TemplateToken> &tokens);
void setOpenCloseCharacters(char openChar,char closeChar)
{ m_openChar=openChar; m_closeChar=closeChar; }
@@ -4553,12 +4553,9 @@ class TemplateLexer
char m_closeChar;
};
TemplateLexer::TemplateLexer(const TemplateEngine *engine,const QCString &fileName,const char *data,int size) :
m_engine(engine), m_fileName(fileName)
TemplateLexer::TemplateLexer(const TemplateEngine *engine,const QCString &fileName,const QCString &data) :
m_engine(engine), m_fileName(fileName), m_data(data)
{
m_data.resize(size+1);
memcpy(m_data.rawData(),data,size);
m_data[size]=0;
m_openChar='{';
m_closeChar='}';
}
@@ -4908,13 +4905,13 @@ void TemplateParser::warn(const char *fileName,int line,const char *fmt,...) con
//----------------------------------------------------------
TemplateImpl::TemplateImpl(TemplateEngine *engine,const QCString &name,const char *data,int size,
TemplateImpl::TemplateImpl(TemplateEngine *engine,const QCString &name,const QCString &data,
const QCString &extension)
: TemplateNode(0)
{
m_name = name;
m_engine = engine;
TemplateLexer lexer(engine,name,data,size);
TemplateLexer lexer(engine,name,data);
if (extension=="tex")
{
lexer.setOpenCloseCharacters('<','>');
@@ -4988,10 +4985,10 @@ class TemplateEngine::Private
Template *templ = m_templateCache.find(fileName);
if (templ==0)
{
const Resource *res = ResourceMgr::instance().get(fileName);
if (res)
const QCString data = ResourceMgr::instance().getAsString(fileName);
if (!data.isEmpty())
{
templ = new TemplateImpl(m_engine,fileName,(const char *)res->data,res->size,m_extension);
templ = new TemplateImpl(m_engine,fileName,data,m_extension);
m_templateCache.insert(fileName,templ);
}
else

0 comments on commit 15a87a6

Please sign in to comment.