From 312bef563a5be72f6423377247db1b80044bf711 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Fri, 2 Jan 2015 09:56:45 +0100 Subject: Fixed a couple of cases where sharing string data could lead to corruption Also made dangerous string access more visible by introducing rawData(). This replaces data() which will now return a constant string. --- qtools/qcstring.cpp | 48 +++++++++++++++++++++++----------------------- qtools/qcstring.h | 50 ++++++++++++++++++++++++++++++++---------------- qtools/qtextcodec.cpp | 4 ++-- qtools/qtextstream.cpp | 6 +++--- qtools/qutfcodec.cpp | 6 +++--- src/cite.cpp | 2 +- src/config.l | 10 +++++----- src/definition.cpp | 2 +- src/dirdef.cpp | 2 +- src/docparser.cpp | 10 ++++++---- src/dot.cpp | 31 +++++++++++++++--------------- src/htags.cpp | 4 +++- src/htmlgen.cpp | 6 +++--- src/htmlhelp.cpp | 4 ++-- src/markdown.cpp | 2 +- src/marshal.cpp | 2 +- src/memberdef.cpp | 2 +- src/membergroup.cpp | 2 +- src/resourcemgr.cpp | 4 ++-- src/rtfgen.cpp | 7 +++++-- src/tclscanner.l | 8 ++++---- src/template.cpp | 4 ++-- src/tooltip.cpp | 2 +- src/util.cpp | 18 ++++++++--------- src/vhdlcode.l | 4 ++-- src/vhdljjparser.cpp | 2 +- src/xmlgen.cpp | 2 +- vhdlparser/VhdlParser.h | 2 +- vhdlparser/vhdlparser.jj | 2 +- 29 files changed, 137 insertions(+), 111 deletions(-) diff --git a/qtools/qcstring.cpp b/qtools/qcstring.cpp index 49bf842..26df166 100644 --- a/qtools/qcstring.cpp +++ b/qtools/qcstring.cpp @@ -31,7 +31,7 @@ QCString &QCString::sprintf( const char *format, ... ) const int minlen=256; int l = length(); if (l=l) return -1; // index outside string if (!str) return -1; // no string to search for if (!*str) return index; // empty string matching at index - register char *pos; + register const char *pos; if (cs) // case sensitive { pos = strstr(data()+index,str); @@ -132,7 +132,7 @@ int QCString::findRev( const char *str, int index, bool cs) const else if (index>len) return -1; // bad index else if (index+slen>len) index=len-slen; // str would be too long if (index<0) return -1; // no match possible - register char *pos = data()+index; + register const char *pos = data()+index; if (cs) // case sensitive { for (int i=index; i>=0; i--) if (qstrncmp(pos--,str,slen)==0) return i; @@ -204,9 +204,7 @@ bool QCString::stripPrefix(const char *prefix) int len = qstrlen(prefix); if (qstrncmp(prefix,data(),len)==0) { - int newlen = length()-len+1; - qmemmove(data(),data()+len,newlen); - resize(newlen); + m_rep=mid(len,length()-len).m_rep; // need to make a deep copy return TRUE; } return FALSE; @@ -225,7 +223,7 @@ QCString QCString::left( uint len ) const else { QCString s( len+1 ); - memcpy( s.data(), data(), len); + memcpy( s.rawData(), data(), len); return s; } } @@ -255,9 +253,9 @@ QCString QCString::mid( uint index, uint len) const } else { - register char *p = data()+index; + register const char *p = data()+index; QCString s(len+1); - qstrncpy( s.data(), p, len+1 ); + qstrncpy( s.rawData(), p, len+1 ); return s; } } @@ -266,7 +264,7 @@ QCString QCString::lower() const { if (length()==0) return QCString(); QCString s(data()); - register char *pos = s.data(); + register char *pos = s.rawData(); if (pos) { while (*pos) @@ -282,7 +280,7 @@ QCString QCString::upper() const { if (length()==0) return QCString(); QCString s(data()); - register char *pos = s.data(); + register char *pos = s.rawData(); if (pos) { while (*pos) @@ -299,13 +297,13 @@ QCString QCString::stripWhiteSpace() const if ( isEmpty() ) // nothing to do return *this; - register char *s = data(); + register const char *cs = data(); int reslen = length(); - if ( !isspace((uchar)s[0]) && !isspace((uchar)s[reslen-1]) ) + if ( !isspace((uchar)cs[0]) && !isspace((uchar)cs[reslen-1]) ) return *this; // returns a copy - QCString result(s); - s = result.data(); + QCString result(cs); + register char *s = result.rawData(); int start = 0; int end = reslen - 1; while ( isspace((uchar) s[start]) ) // skip white space from start @@ -317,7 +315,7 @@ QCString QCString::stripWhiteSpace() const while ( end && isspace((uchar) s[end]) ) // skip white space from end end--; end -= start - 1; - qmemmove( result.data(), &s[start], end ); + qmemmove( s, &s[start], end ); result.resize( end + 1 ); return result; } @@ -328,8 +326,8 @@ QCString QCString::simplifyWhiteSpace() const return *this; QCString result( length()+1 ); - char *from = data(); - char *to = result.data(); + const char *from = data(); + char *to = result.rawData(); char *first = to; while ( TRUE ) { @@ -363,14 +361,14 @@ QCString &QCString::insert( uint index, const char *s ) if ((int)index>=olen) { resize(nlen+index-olen+1); - memset(data()+olen, ' ', index-olen); - memcpy(data()+index,s, len+1); + memset(rawData()+olen, ' ', index-olen); + memcpy(rawData()+index,s, len+1); } else { resize(nlen+1); - qmemmove(data()+index+len,data()+index,olen-index+1); - memcpy(data()+index,s,len); + qmemmove(rawData()+index+len,data()+index,olen-index+1); + memcpy(rawData()+index,s,len); } return *this; } @@ -402,8 +400,10 @@ QCString &QCString::remove( uint index, uint len ) } else if ( len != 0 ) { - qmemmove( data()+index, data()+index+len, olen-index-len+1 ); + QCString tmp(olen-index-len+1); + qmemmove( tmp.rawData(), data()+index+len, olen-index-len+1 ); resize( olen-len+1 ); + memcpy( rawData()+index,tmp.data(),tmp.length() ); } return *this; } @@ -635,7 +635,7 @@ QDataStream &operator>>( QDataStream &s, QCString &str ) len = 0; } if ( len > 0 ) // not null array - s.readRawBytes( str.data(), (uint)len ); + s.readRawBytes( str.rawData(), (uint)len ); return s; } diff --git a/qtools/qcstring.h b/qtools/qcstring.h index bc3a091..8854aa7 100644 --- a/qtools/qcstring.h +++ b/qtools/qcstring.h @@ -204,11 +204,20 @@ public: } /** Returns a pointer to the contents of the string in the form of a 0-terminated C string */ - char *data() const + const char *data() const { return m_rep.data(); } + /** Returns a writable pointer to the data. + * @warning if the string is shared it will modifying the string directly and + * this will overwrite all copies as well! + */ + char *rawData() const + { + return m_rep.rawData(); + } + /** Resizes the string to hold \a newlen characters * (this value should include the 0-terminator). If the string is enlarged the contents will * be left unmodified. @@ -242,7 +251,7 @@ public: { if (length()==0) return QCString(); QCString cs(length()+1); - memcpy(cs.data(),data(),length()); + memcpy(cs.rawData(),data(),length()); return cs; } @@ -299,7 +308,7 @@ public: int len1 = length(); int len2 = (int)strlen(str); resize(len1+len2+1); - memcpy(data()+len1,str,len2); + memcpy(rawData()+len1,str,len2); return *this; } @@ -308,7 +317,7 @@ public: { int len = length(); resize(len+2); - data()[len]=c; + rawData()[len]=c; return *this; } @@ -568,9 +577,21 @@ public: } uint length() const { - return u.s.isShort ? u.s.len : u.l.d->len; + uint l = u.s.isShort ? u.s.len : u.l.d->len; + return l; } - char *data() const + const char *data() const + { + if (u.s.isShort) + { + return u.s.len==0 ? 0 : u.s.str; + } + else + { + return u.l.d->len==0 ? 0 : u.l.d->toStr(); + } + } + char *rawData() const { if (u.s.isShort) { @@ -578,6 +599,7 @@ public: } else { + //assert(u.l.d->refCount==0); // string may not be shared when accessed raw return u.l.d->len==0 ? 0 : u.l.d->toStr(); } } @@ -645,24 +667,20 @@ public: bool fill( char c, int len ) { if (len<0) len=length(); - if (len!=(int)length()) + if (!u.s.isShort) // detach from shared string + { + resize(len+1); + } + else if (len!=(int)length()) { if (len>0) { resize(len+1); } - else - { - if (!u.s.isShort) - { - u.l.d->dispose(); - } - initEmpty(); - } } if (len>0) { - memset(data(),c,len); + memset(rawData(),c,len); } return TRUE; } diff --git a/qtools/qtextcodec.cpp b/qtools/qtextcodec.cpp index 168445f..bd874bb 100644 --- a/qtools/qtextcodec.cpp +++ b/qtools/qtextcodec.cpp @@ -1192,7 +1192,7 @@ public: lenInOut = uc.length(); int rlen = lenInOut*max_bytes_per_char; QCString rstr(rlen); - char* cursor = rstr.data(); + char* cursor = rstr.rawData(); char* s=0; int l = lenInOut; int lout = 0; @@ -1881,7 +1881,7 @@ QCString QSimpleTextCodec::fromUnicode(const QString& uc, int& len ) const int i = len; int u; const QChar* ucp = uc.unicode(); - char* rp = r.data(); + char* rp = r.rawData(); char* rmp = reverseMap->data(); int rmsize = (int) reverseMap->size(); while( i-- ) diff --git a/qtools/qtextstream.cpp b/qtools/qtextstream.cpp index bae072d..4ebf59e 100644 --- a/qtools/qtextstream.cpp +++ b/qtools/qtextstream.cpp @@ -1443,17 +1443,17 @@ QTextStream &QTextStream::operator>>( QCString &str ) if ( i >= buflen-1 ) { if ( !dynbuf ) { // create dynamic buffer dynbuf = new QCString(buflen*2); - memcpy( dynbuf->data(), s, i ); // copy old data + memcpy( dynbuf->rawData(), s, i ); // copy old data } else if ( i >= (int)dynbuf->size()-1 ) { dynbuf->resize( dynbuf->size()*2 ); } - s = dynbuf->data(); + s = dynbuf->rawData(); } s[i++] = c; c = ts_getc(); } str.resize( i+1 ); - memcpy( str.data(), s, i ); + memcpy( str.rawData(), s, i ); delete dynbuf; return *this; } diff --git a/qtools/qutfcodec.cpp b/qtools/qutfcodec.cpp index c7094ad..a37e37f 100644 --- a/qtools/qutfcodec.cpp +++ b/qtools/qutfcodec.cpp @@ -203,14 +203,14 @@ public: if ( headerdone ) { len_in_out = uc.length()*(int)sizeof(QChar); QCString d(len_in_out); - memcpy(d.data(),uc.unicode(),len_in_out); + memcpy(d.rawData(),uc.unicode(),len_in_out); return d; } else { headerdone = TRUE; len_in_out = (1+uc.length())*(int)sizeof(QChar); QCString d(len_in_out); - memcpy(d.data(),&QChar::byteOrderMark,sizeof(QChar)); - memcpy(d.data()+sizeof(QChar),uc.unicode(),uc.length()*sizeof(QChar)); + memcpy(d.rawData(),&QChar::byteOrderMark,sizeof(QChar)); + memcpy(d.rawData()+sizeof(QChar),uc.unicode(),uc.length()*sizeof(QChar)); return d; } } diff --git a/src/cite.cpp b/src/cite.cpp index f0d7d66..e42a6d6 100644 --- a/src/cite.cpp +++ b/src/cite.cpp @@ -211,7 +211,7 @@ void CiteDict::generatePage() const QCString doc; QFileInfo fi(citeListFile); QCString input(fi.size()+1); - f.readBlock(input.data(),fi.size()); + f.readBlock(input.rawData(),fi.size()); f.close(); input.at(fi.size())='\0'; int p=0,s; diff --git a/src/config.l b/src/config.l index a237faf..2adbbc7 100644 --- a/src/config.l +++ b/src/config.l @@ -85,7 +85,7 @@ static QCString convertToComment(const QCString &s, const QCString &u) if (!s.isEmpty()) { QCString tmp=s.stripWhiteSpace(); - char *p=tmp.data(); + const char *p=tmp.data(); char c; result+="#"; if (*p && *p!='\n') @@ -495,8 +495,8 @@ static QCString configStringRecode( } size_t iLeft=(size_t)inputSize; size_t oLeft=(size_t)outputSize; - char *inputPtr = str.data(); - char *outputPtr = output.data(); + char *inputPtr = str.rawData(); + char *outputPtr = output.rawData(); if (!portable_iconv(cd, &inputPtr, &iLeft, &outputPtr, &oLeft)) { outputSize-=(int)oLeft; @@ -1695,7 +1695,7 @@ static QCString configFileToString(const char *name) QCString contents(bSize); int totalSize=0; int size; - while ((size=f.readBlock(contents.data()+totalSize,bSize))==bSize) + while ((size=f.readBlock(contents.rawData()+totalSize,bSize))==bSize) { totalSize+=bSize; contents.resize(totalSize+bSize); @@ -1721,7 +1721,7 @@ static QCString configFileToString(const char *name) { int fsize=f.size(); QCString contents(fsize+2); - f.readBlock(contents.data(),fsize); + f.readBlock(contents.rawData(),fsize); f.close(); if (fsize==0 || contents[fsize-1]=='\n') contents[fsize]='\0'; diff --git a/src/definition.cpp b/src/definition.cpp index 6cb26de..8014a37 100644 --- a/src/definition.cpp +++ b/src/definition.cpp @@ -543,7 +543,7 @@ bool Definition::_docsAlreadyAdded(const QCString &doc,QCString &sigList) // double whitespaces... QCString docStr = doc.simplifyWhiteSpace(); MD5Buffer((const unsigned char *)docStr.data(),docStr.length(),md5_sig); - MD5SigToString(md5_sig,sigStr.data(),33); + MD5SigToString(md5_sig,sigStr.rawData(),33); //printf("%s:_docsAlreadyAdded doc='%s' sig='%s' docSigs='%s'\n", // name().data(),doc.data(),sigStr.data(),sigList.data()); if (sigList.find(sigStr)==-1) // new docs, add signature to prevent re-adding it diff --git a/src/dirdef.cpp b/src/dirdef.cpp index d4af3f0..37b4c55 100644 --- a/src/dirdef.cpp +++ b/src/dirdef.cpp @@ -86,7 +86,7 @@ static QCString encodeDirName(const QCString &anchor) uchar md5_sig[16]; QCString sigStr(33); MD5Buffer((const unsigned char *)anchor.data(),anchor.length(),md5_sig); - MD5SigToString(md5_sig,sigStr.data(),33); + MD5SigToString(md5_sig,sigStr.rawData(),33); return sigStr; // old algorithm diff --git a/src/docparser.cpp b/src/docparser.cpp index 9a120dc..540eb91 100644 --- a/src/docparser.cpp +++ b/src/docparser.cpp @@ -236,7 +236,8 @@ static void docParserPopContext(bool keepParamInfo=FALSE) // replaces > with < and > with > within string s static void unescapeCRef(QCString &s) { - char *p = s.data(); + QCString tmp(s); + char *p = tmp.rawData(); if (p) { char c; @@ -247,8 +248,9 @@ static void unescapeCRef(QCString &s) } } - s=substitute(s,"<","<"); - s=substitute(s,">",">"); + tmp=substitute(tmp,"<","<"); + tmp=substitute(tmp,">",">"); + s = tmp; } //--------------------------------------------------------------------------- @@ -6939,7 +6941,7 @@ static QCString extractCopyDocId(const char *data, uint &j, uint len) } e=j; QCString id(e-s+1); - if (e>s) memcpy(id.data(),data+s,e-s); + if (e>s) memcpy(id.rawData(),data+s,e-s); id.at(e-s)='\0'; //printf("extractCopyDocId='%s' input='%s'\n",id.data(),&data[s]); return id; diff --git a/src/dot.cpp b/src/dot.cpp index f9b4302..20dd1e6 100644 --- a/src/dot.cpp +++ b/src/dot.cpp @@ -383,7 +383,7 @@ static bool convertMapFile(FTextStream &t,const char *mapName, while (!f.atEnd()) // foreach line { QCString buf(maxLineLen); - int numBytes = f.readLine(buf.data(),maxLineLen); + int numBytes = f.readLine(buf.rawData(),maxLineLen); buf[numBytes-1]='\0'; if (buf.left(5)=="relPath,map->urlOnly,map->context,"_top"); } @@ -1964,8 +1965,8 @@ void DotNode::writeXML(FTextStream &t,bool isClassGraph) if (!m_url.isEmpty()) { QCString url(m_url); - char *refPtr = url.data(); - char *urlPtr = strchr(url.data(),'$'); + const char *refPtr = url.data(); + char *urlPtr = strchr(url.rawData(),'$'); if (urlPtr) { *urlPtr++='\0'; @@ -2032,8 +2033,8 @@ void DotNode::writeDocbook(FTextStream &t,bool isClassGraph) if (!m_url.isEmpty()) { QCString url(m_url); - char *refPtr = url.data(); - char *urlPtr = strchr(url.data(),'$'); + const char *refPtr = url.data(); + char *urlPtr = strchr(url.rawData(),'$'); if (urlPtr) { *urlPtr++='\0'; @@ -2105,8 +2106,8 @@ void DotNode::writeDEF(FTextStream &t) if (!m_url.isEmpty()) { QCString url(m_url); - char *refPtr = url.data(); - char *urlPtr = strchr(url.data(),'$'); + const char *refPtr = url.data(); + char *urlPtr = strchr(url.rawData(),'$'); if (urlPtr) { *urlPtr++='\0'; @@ -2300,7 +2301,7 @@ void DotGfxHierarchyTable::createGraph(DotNode *n,FTextStream &out, uchar md5_sig[16]; QCString sigStr(33); MD5Buffer((const unsigned char *)theGraph.data(),theGraph.length(),md5_sig); - MD5SigToString(md5_sig,sigStr.data(),33); + MD5SigToString(md5_sig,sigStr.rawData(),33); bool regenerate=FALSE; if (checkAndUpdateMd5Signature(absBaseName,sigStr) || !checkDeliverables(absImgName,absMapName)) @@ -3028,7 +3029,7 @@ QCString computeMd5Signature(DotNode *root, uchar md5_sig[16]; QCString sigStr(33); MD5Buffer((const unsigned char *)buf.data(),buf.length(),md5_sig); - MD5SigToString(md5_sig,sigStr.data(),33); + MD5SigToString(md5_sig,sigStr.rawData(),33); if (reNumber) { resetReNumbering(); @@ -3962,7 +3963,7 @@ QCString DotDirDeps::writeGraph(FTextStream &out, uchar md5_sig[16]; QCString sigStr(33); MD5Buffer((const unsigned char *)theGraph.data(),theGraph.length(),md5_sig); - MD5SigToString(md5_sig,sigStr.data(),33); + MD5SigToString(md5_sig,sigStr.rawData(),33); bool regenerate=FALSE; if (checkAndUpdateMd5Signature(absBaseName,sigStr) || !checkDeliverables(graphFormat==GOF_BITMAP ? absImgName : @@ -4108,7 +4109,7 @@ void generateGraphLegend(const char *path) uchar md5_sig[16]; QCString sigStr(33); MD5Buffer((const unsigned char *)theGraph.data(),theGraph.length(),md5_sig); - MD5SigToString(md5_sig,sigStr.data(),33); + MD5SigToString(md5_sig,sigStr.rawData(),33); QCString absBaseName = (QCString)path+"/graph_legend"; QCString absDotName = absBaseName+".dot"; QCString imgExt = Config_getEnum("DOT_IMAGE_FORMAT"); @@ -4508,7 +4509,7 @@ QCString DotGroupCollaboration::writeGraph( FTextStream &t, uchar md5_sig[16]; QCString sigStr(33); MD5Buffer((const unsigned char *)theGraph.data(),theGraph.length(),md5_sig); - MD5SigToString(md5_sig,sigStr.data(),33); + MD5SigToString(md5_sig,sigStr.rawData(),33); QCString imgExt = Config_getEnum("DOT_IMAGE_FORMAT"); QCString baseName = m_diskName; QCString imgName = baseName+"."+imgExt; diff --git a/src/htags.cpp b/src/htags.cpp index 1e18ae1..cbf4aa8 100644 --- a/src/htags.cpp +++ b/src/htags.cpp @@ -126,8 +126,10 @@ bool Htags::loadFilemap(const QCString &htmlDir) line.at(maxlen)='\0'; if (f.open(IO_ReadOnly)) { - while (f.readLine(line.data(),maxlen)>0) + int len; + while ((len=f.readLine(line.rawData(),maxlen))>0) { + line.resize(len+1); //printf("Read line: %s",line.data()); int sep = line.find('\t'); if (sep!=-1) diff --git a/src/htmlgen.cpp b/src/htmlgen.cpp index 3bb6792..582da45 100644 --- a/src/htmlgen.cpp +++ b/src/htmlgen.cpp @@ -125,7 +125,7 @@ QCString clearBlock(const char *s,const char *begin,const char *end) QCString result(resLen+1); char *r; - for (r=result.data(), p=s; (q=strstr(p,begin))!=0; p=q+endLen) + for (r=result.rawData(), p=s; (q=strstr(p,begin))!=0; p=q+endLen) { int l = (int)(q-p); memcpy(r,p,l); @@ -186,7 +186,7 @@ static QCString getSearchBox(bool serverSide, QCString relPath, bool highlightSe static QCString removeEmptyLines(const QCString &s) { BufStr out(s.length()+1); - char *p=s.data(); + const char *p=s.data(); if (p) { char c; @@ -194,7 +194,7 @@ static QCString removeEmptyLines(const QCString &s) { if (c=='\n') { - char *e = p; + const char *e = p; while (*e==' ' || *e=='\t') e++; if (*e=='\n') { diff --git a/src/htmlhelp.cpp b/src/htmlhelp.cpp index 2629ab3..7c12890 100644 --- a/src/htmlhelp.cpp +++ b/src/htmlhelp.cpp @@ -599,8 +599,8 @@ QCString HtmlHelp::recode(const QCString &s) QCString output(oSize); size_t iLeft = iSize; size_t oLeft = oSize; - char *iPtr = s.data(); - char *oPtr = output.data(); + char *iPtr = s.rawData(); + char *oPtr = output.rawData(); if (!portable_iconv(m_fromUtf8,&iPtr,&iLeft,&oPtr,&oLeft)) { oSize -= (int)oLeft; diff --git a/src/markdown.cpp b/src/markdown.cpp index fdf1b0f..414aa19 100644 --- a/src/markdown.cpp +++ b/src/markdown.cpp @@ -132,7 +132,7 @@ static void convertStringFragment(QCString &result,const char *data,int size) { if (size<0) size=0; result.resize(size+1); - memcpy(result.data(),data,size); + memcpy(result.rawData(),data,size); result.at(size)='\0'; } diff --git a/src/marshal.cpp b/src/marshal.cpp index 04f426d..af14978 100644 --- a/src/marshal.cpp +++ b/src/marshal.cpp @@ -456,7 +456,7 @@ QCString unmarshalQCString(StorageIntf *s) result.at(len)='\0'; if (len>0) { - s->read(result.data(),len); + s->read(result.rawData(),len); } //printf("unmarshalQCString: result=%s\n",result.data()); return result; diff --git a/src/memberdef.cpp b/src/memberdef.cpp index 72f3e3c..375260e 100644 --- a/src/memberdef.cpp +++ b/src/memberdef.cpp @@ -3331,7 +3331,7 @@ void MemberDef::setAnchor() QCString sigStr(33); MD5Buffer((const unsigned char *)memAnchor.data(),memAnchor.length(),md5_sig); //printf("memAnchor=%s\n",memAnchor.data()); - MD5SigToString(md5_sig,sigStr.data(),33); + MD5SigToString(md5_sig,sigStr.rawData(),33); m_impl->anc = "a"+sigStr; } diff --git a/src/membergroup.cpp b/src/membergroup.cpp index aa0a36e..d073173 100644 --- a/src/membergroup.cpp +++ b/src/membergroup.cpp @@ -312,7 +312,7 @@ QCString MemberGroup::anchor() const QCString locHeader = grpHeader; if (locHeader.isEmpty()) locHeader="[NOHEADER]"; MD5Buffer((const unsigned char *)locHeader.data(),locHeader.length(),md5_sig); - MD5SigToString(md5_sig,sigStr.data(),33); + MD5SigToString(md5_sig,sigStr.rawData(),33); return "amgrp"+sigStr; } diff --git a/src/resourcemgr.cpp b/src/resourcemgr.cpp index a15a702..4b504e4 100644 --- a/src/resourcemgr.cpp +++ b/src/resourcemgr.cpp @@ -132,7 +132,7 @@ bool ResourceMgr::copyResourceAs(const char *name,const char *targetDir,const ch if (f.open(IO_WriteOnly)) { QCString buf(res->size+1); - memcpy(buf.data(),res->data,res->size); + memcpy(buf.rawData(),res->data,res->size); FTextStream t(&f); buf = replaceColorMarkers(buf); if (qstrcmp(name,"navtree.css")==0) @@ -172,7 +172,7 @@ QCString ResourceMgr::getAsString(const char *name) const if (res) { QCString result(res->size+1); - memcpy(result.data(),res->data,res->size); + memcpy(result.rawData(),res->data,res->size); return result; } else diff --git a/src/rtfgen.cpp b/src/rtfgen.cpp index 354469b..2a6fd07 100644 --- a/src/rtfgen.cpp +++ b/src/rtfgen.cpp @@ -2362,19 +2362,22 @@ static bool preProcessFile(QDir &d,QCString &infName, FTextStream &t, bool bIncl // this is EXTREEEEEEEMLY brittle. It works on OUR rtf // files because the first line before the body // ALWAYS contains "{\comment begin body}" + int len; do { - if (f.readLine(lineBuf.data(),maxLineLength)==-1) + if ((len=f.readLine(lineBuf.rawData(),maxLineLength))==-1) { err("read error in %s before end of RTF header!\n",infName.data()); return FALSE; } + lineBuf.resize(len+1); if (bIncludeHeader) encodeForOutput(t,lineBuf.data()); } while (lineBuf.find("\\comment begin body")==-1); - while (f.readLine(lineBuf.data(),maxLineLength)!=-1) + while ((len=f.readLine(lineBuf.rawData(),maxLineLength))!=-1) { + lineBuf.resize(len+1); int pos; if ((pos=lineBuf.find("INCLUDETEXT"))!=-1) { diff --git a/src/tclscanner.l b/src/tclscanner.l index f162637..198fd85 100644 --- a/src/tclscanner.l +++ b/src/tclscanner.l @@ -657,7 +657,7 @@ static void tcl_font_end() } //! Codify 'str' with special font class 's'. -static void tcl_codify(const char *s,char *str) +static void tcl_codify(const char *s,const char *str) { if (!tcl.code || !str) return; if (s && qstrcmp(s,"NULL")!=0) @@ -666,7 +666,7 @@ static void tcl_codify(const char *s,char *str) tcl.code->startFontClass(s); tcl.code_font=s; } - char *p=str,*sp=p; + const char *p=str,*sp=p; char c; bool done=FALSE; while (!done) @@ -676,7 +676,7 @@ static void tcl_codify(const char *s,char *str) if (c=='\n') { tcl.code_line++; - *(p-1)='\0'; + // *(p-1)='\0'; // Dimitri: is this really needed? tcl.code->codify(sp); if (tcl.code_font) { @@ -719,7 +719,6 @@ static void tcl_codify(const char *s,const QString &str) if (tcl.code==NULL) return; tcl_codify(s,str.utf8()); } -#endif //! Codify 'str' with special font class 's'. static void tcl_codify(const char *s,const QCString &str) @@ -727,6 +726,7 @@ static void tcl_codify(const char *s,const QCString &str) if (!tcl.code) return; tcl_codify(s,str.data()); } +#endif static void tcl_codify_cmd(const char *s,int i) { diff --git a/src/template.cpp b/src/template.cpp index 9fa03aa..a9fab94 100644 --- a/src/template.cpp +++ b/src/template.cpp @@ -4395,7 +4395,7 @@ TemplateLexer::TemplateLexer(const TemplateEngine *engine,const QCString &fileNa m_engine(engine), m_fileName(fileName) { m_data.resize(size+1); - memcpy(m_data.data(),data,size); + memcpy(m_data.rawData(),data,size); m_data[size]=0; } @@ -4602,7 +4602,7 @@ void TemplateLexer::addToken(QList &tokens, { int len = endPos-startPos+1; QCString text(len); - qstrncpy(text.data(),data+startPos,len); + qstrncpy(text.rawData(),data+startPos,len); if (type!=TemplateToken::Text) text = text.stripWhiteSpace(); tokens.append(new TemplateToken(type,text,line)); } diff --git a/src/tooltip.cpp b/src/tooltip.cpp index 8085bff..8db0394 100644 --- a/src/tooltip.cpp +++ b/src/tooltip.cpp @@ -59,7 +59,7 @@ void TooltipManager::clearTooltips() static QCString escapeId(const char *s) { QCString res=s; - char *p=res.data(); + char *p=res.rawData(); while (*p) { if (!isId(*p)) *p='_'; diff --git a/src/util.cpp b/src/util.cpp index 000de53..1639e0a 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1448,7 +1448,7 @@ static ClassDef *getResolvedClassRec(Definition *scope, // below is a more efficient coding of // QCString key=scope->name()+"+"+name+"+"+explicitScopePart; QCString key(scopeNameLen+nameLen+explicitPartLen+fileScopeLen+1); - char *p=key.data(); + char *p=key.rawData(); qstrcpy(p,scope->name()); *(p+scopeNameLen-1)='+'; p+=scopeNameLen; qstrcpy(p,name); *(p+nameLen-1)='+'; @@ -2379,8 +2379,8 @@ QCString transcodeCharacterStringToUTF8(const QCString &input) { size_t iLeft=inputSize; size_t oLeft=outputSize; - char *inputPtr = input.data(); - char *outputPtr = output.data(); + char *inputPtr = input.rawData(); + char *outputPtr = output.rawData(); if (!portable_iconv(cd, &inputPtr, &iLeft, &outputPtr, &oLeft)) { outputSize-=(int)oLeft; @@ -2418,12 +2418,12 @@ QCString fileToString(const char *name,bool filter,bool isSourceCode) QCString contents(bSize); int totalSize=0; int size; - while ((size=f.readBlock(contents.data()+totalSize,bSize))==bSize) + while ((size=f.readBlock(contents.rawData()+totalSize,bSize))==bSize) { totalSize+=bSize; - contents.resize(totalSize+bSize); + contents.resize(totalSize+bSize); } - totalSize = filterCRLF(contents.data(),totalSize+size)+2; + totalSize = filterCRLF(contents.rawData(),totalSize+size)+2; contents.resize(totalSize); contents.at(totalSize-2)='\n'; // to help the scanner contents.at(totalSize-1)='\0'; @@ -5060,7 +5060,7 @@ QCString substitute(const QCString &s,const QCString &src,const QCString &dst) } QCString result(resLen+1); char *r; - for (r=result.data(), p=s; (q=strstr(p,src))!=0; p=q+srcLen) + for (r=result.rawData(), p=s; (q=strstr(p,src))!=0; p=q+srcLen) { int l = (int)(q-p); memcpy(r,p,l); @@ -5340,7 +5340,7 @@ QCString convertNameToFile(const char *name,bool allowDots,bool allowUnderscore) uchar md5_sig[16]; QCString sigStr(33); MD5Buffer((const unsigned char *)result.data(),resultLen,md5_sig); - MD5SigToString(md5_sig,sigStr.data(),33); + MD5SigToString(md5_sig,sigStr.rawData(),33); result=result.left(128-32)+sigStr; } } @@ -6550,7 +6550,7 @@ QCString rtfFormatBmkStr(const char *name) g_tagDict.insert( key, tag ); // This is the increment part - char* nxtTag = g_nextTag.data() + g_nextTag.length() - 1; + char* nxtTag = g_nextTag.rawData() + g_nextTag.length() - 1; for ( unsigned int i = 0; i < g_nextTag.length(); ++i, --nxtTag ) { if ( ( ++(*nxtTag) ) > 'Z' ) diff --git a/src/vhdlcode.l b/src/vhdlcode.l index fa199d1..5f328af 100644 --- a/src/vhdlcode.l +++ b/src/vhdlcode.l @@ -620,7 +620,7 @@ static void appStringLower(QCString& qcs,const char* text) static QCString g_temp; /* writes and links a port map statement */ -static void codifyMapLines(char *text) +static void codifyMapLines(const char *text) { if (text==0) return; g_temp.resize(0); @@ -628,7 +628,7 @@ static void codifyMapLines(char *text) int wordCounter=0; QCString ctemp; //printf("codifyLines(%d,\"%s\")\n",g_yyLineNr,text); - char *p=text; //,*sp=p; + const char *p=text; //,*sp=p; char c; bool done=FALSE; while (!done) diff --git a/src/vhdljjparser.cpp b/src/vhdljjparser.cpp index 7b0c112..c3f8663 100644 --- a/src/vhdljjparser.cpp +++ b/src/vhdljjparser.cpp @@ -396,7 +396,7 @@ void VHDLLanguageScanner::parsePrototype(const char *text) varr=TRUE; } -void VhdlParser::addCompInst(char *n, char* instName, char* comp,int iLine) +void VhdlParser::addCompInst(const char *n, const char* instName, const char* comp,int iLine) { current->spec=VhdlDocGen::INSTANTIATION; current->section=Entry::VARIABLE_SEC; diff --git a/src/xmlgen.cpp b/src/xmlgen.cpp index 8e1d02f..8319922 100644 --- a/src/xmlgen.cpp +++ b/src/xmlgen.cpp @@ -1865,7 +1865,7 @@ void generateXML() if (len>0) { QCString s(len+1); - qstrncpy(s.data(),startLine,len); + qstrncpy(s.rawData(),startLine,len); s[len]='\0'; if (s.find("")!=-1) { diff --git a/vhdlparser/VhdlParser.h b/vhdlparser/VhdlParser.h index 12631dd..e4c92d0 100644 --- a/vhdlparser/VhdlParser.h +++ b/vhdlparser/VhdlParser.h @@ -8976,7 +8976,7 @@ static void addProto(const char *s1,const char *s2,const char *s3,const char *s4 static void addConfigureNode(const char* a,const char*b, bool,bool isLeaf,bool inlineConf); static void createFunction(const char *impure,uint64 spec,const char *fname); static void addVhdlType(const char *n,int startLine,int section, uint64 spec,const char* args,const char* type,Protection prot); -static void addCompInst(char *n, char* instName, char* comp,int iLine); +static void addCompInst(const char *n, const char* instName, const char* comp,int iLine); static void handleCommentBlock(const char* doc,bool brief); static void handleFlowComment(const char*); static void initEntry(Entry *e); diff --git a/vhdlparser/vhdlparser.jj b/vhdlparser/vhdlparser.jj index 0225183..aa42127 100644 --- a/vhdlparser/vhdlparser.jj +++ b/vhdlparser/vhdlparser.jj @@ -55,7 +55,7 @@ static void addProto(const char *s1,const char *s2,const char *s3,const char *s4 static void addConfigureNode(const char* a,const char*b, bool,bool isLeaf,bool inlineConf); static void createFunction(const char *impure,uint64 spec,const char *fname); static void addVhdlType(const char *n,int startLine,int section, uint64 spec,const char* args,const char* type,Protection prot); -static void addCompInst(char *n, char* instName, char* comp,int iLine); +static void addCompInst(const char *n, const char* instName, const char* comp,int iLine); static void handleCommentBlock(const char* doc,bool brief); static void handleFlowComment(const char*); static void initEntry(Entry *e); -- cgit v0.12