--------------------- PatchSet 4459 Date: 2007/05/07 10:32:21 Author: amosjeffries Branch: ayjwork Tag: (none) Log: Be String-safe. Fixup some areas slightly to use string API better. Members: src/DelayTagged.cc:1.3.24.2->1.3.24.3 src/ESI.cc:1.22.8.2->1.22.8.3 src/ESIVarState.cc:1.7.8.2->1.7.8.3 src/HttpHdrSc.cc:1.5.8.4->1.5.8.5 src/HttpReply.cc:1.38.4.4->1.38.4.5 src/SqString.cc:1.1.2.2->1.1.2.3 src/SqString.h:1.1.2.2->1.1.2.3 src/SquidString.h:1.8.8.4->1.8.8.5 src/store.cc:1.51.4.4->1.51.4.5 src/store_log.cc:1.6.2.3->1.6.2.4 src/ICAP/ICAPOptions.cc:1.9.4.1->1.9.4.2 src/ICAP/ICAPServiceRep.cc:1.7.4.4->1.7.4.5 Index: squid3/src/DelayTagged.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/DelayTagged.cc,v retrieving revision 1.3.24.2 retrieving revision 1.3.24.3 diff -u -r1.3.24.2 -r1.3.24.3 --- squid3/src/DelayTagged.cc 3 May 2007 13:37:05 -0000 1.3.24.2 +++ squid3/src/DelayTagged.cc 7 May 2007 10:32:21 -0000 1.3.24.3 @@ -1,6 +1,6 @@ /* - * $Id: DelayTagged.cc,v 1.3.24.2 2007/05/03 13:37:05 amosjeffries Exp $ + * $Id: DelayTagged.cc,v 1.3.24.3 2007/05/07 10:32:21 amosjeffries Exp $ * * DEBUG: section 77 Delay Pools * AUTHOR: Robert Collins @@ -77,7 +77,7 @@ DelayTaggedCmp(DelayTaggedBucket::Pointer const &left, DelayTaggedBucket::Pointer const &right) { /* for rate limiting, case insensitive */ - return left->tag.caseCmp(right->tag.c_str()); + return strcasecmp(left->tag, right->tag); } void Index: squid3/src/ESI.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ESI.cc,v retrieving revision 1.22.8.2 retrieving revision 1.22.8.3 diff -u -r1.22.8.2 -r1.22.8.3 --- squid3/src/ESI.cc 3 May 2007 15:03:33 -0000 1.22.8.2 +++ squid3/src/ESI.cc 7 May 2007 10:32:21 -0000 1.22.8.3 @@ -1,6 +1,6 @@ /* - * $Id: ESI.cc,v 1.22.8.2 2007/05/03 15:03:33 amosjeffries Exp $ + * $Id: ESI.cc,v 1.22.8.3 2007/05/07 10:32:21 amosjeffries Exp $ * * DEBUG: section 86 ESI processing * AUTHOR: Robert Collins @@ -2450,7 +2450,7 @@ */ return 0; - if (strstr (sctusable->content.c_str(), "ESI/1.0")) + if (strstr (sctusable->content, "ESI/1.0")) rv = 1; httpHdrScTargetDestroy (sctusable); Index: squid3/src/ESIVarState.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ESIVarState.cc,v retrieving revision 1.7.8.2 retrieving revision 1.7.8.3 diff -u -r1.7.8.2 -r1.7.8.3 --- squid3/src/ESIVarState.cc 3 May 2007 15:03:34 -0000 1.7.8.2 +++ squid3/src/ESIVarState.cc 7 May 2007 10:32:22 -0000 1.7.8.3 @@ -1,6 +1,6 @@ /* - * $Id: ESIVarState.cc,v 1.7.8.2 2007/05/03 15:03:34 amosjeffries Exp $ + * $Id: ESIVarState.cc,v 1.7.8.3 2007/05/07 10:32:22 amosjeffries Exp $ * * DEBUG: section 86 ESI processing * AUTHOR: Robert Collins @@ -887,8 +887,7 @@ string strVary (rep->header.getList (HDR_VARY)); - if (!strVary.size() || *strVary.c_str() != '*') { + if (!strVary.size() || strVary[0] != '*') { rep->header.putStr (HDR_VARY, tempstr); } } - Index: squid3/src/HttpHdrSc.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/HttpHdrSc.cc,v retrieving revision 1.5.8.4 retrieving revision 1.5.8.5 diff -u -r1.5.8.4 -r1.5.8.5 --- squid3/src/HttpHdrSc.cc 3 May 2007 10:05:07 -0000 1.5.8.4 +++ squid3/src/HttpHdrSc.cc 7 May 2007 10:32:22 -0000 1.5.8.5 @@ -1,6 +1,6 @@ /* - * $Id: HttpHdrSc.cc,v 1.5.8.4 2007/05/03 10:05:07 amosjeffries Exp $ + * $Id: HttpHdrSc.cc,v 1.5.8.5 2007/05/07 10:32:22 amosjeffries Exp $ * * DEBUG: section 90 HTTP Cache Control Header * AUTHOR: Alex Rousskov @@ -369,9 +369,9 @@ while (node) { HttpHdrScTarget *sct = (HttpHdrScTarget *)node->data; - if (target && sct->target.c_str() && !strcmp (target, sct->target.c_str())) + if (target && !sct->target.empty() && !strcmp(target, sct->target) ) return sct; - else if (!target && !sct->target.c_str()) + else if (!target && sct->target.empty()) return sct; node = node->next; Index: squid3/src/HttpReply.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/HttpReply.cc,v retrieving revision 1.38.4.4 retrieving revision 1.38.4.5 diff -u -r1.38.4.4 -r1.38.4.5 --- squid3/src/HttpReply.cc 3 May 2007 13:37:05 -0000 1.38.4.4 +++ squid3/src/HttpReply.cc 7 May 2007 10:32:22 -0000 1.38.4.5 @@ -1,6 +1,6 @@ /* - * $Id: HttpReply.cc,v 1.38.4.4 2007/05/03 13:37:05 amosjeffries Exp $ + * $Id: HttpReply.cc,v 1.38.4.5 2007/05/07 10:32:22 amosjeffries Exp $ * * DEBUG: section 58 HTTP Reply (Response) * AUTHOR: Alex Rousskov @@ -278,7 +278,7 @@ two = otherRep->header.getStrOrList(HDR_ETAG); - if (!one.c_str() || !two.c_str() || strcasecmp (one, two)) { + if (one.empty() || two.empty() || strcasecmp (one, two)) { return 0; } @@ -290,7 +290,7 @@ two = otherRep->header.getStrOrList(HDR_CONTENT_MD5); - if (!one.c_str() || !two.c_str() || strcasecmp (one, two)) { + if (one.empty() || two.empty() || strcasecmp (one, two)) { one.clear(); two.clear(); return 0; Index: squid3/src/SqString.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/SqString.cc,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- squid3/src/SqString.cc 6 May 2007 03:18:15 -0000 1.1.2.2 +++ squid3/src/SqString.cc 7 May 2007 10:32:22 -0000 1.1.2.3 @@ -1,6 +1,6 @@ /* - * $Id: SqString.cc,v 1.1.2.2 2007/05/06 03:18:15 amosjeffries Exp $ + * $Id: SqString.cc,v 1.1.2.3 2007/05/07 10:32:22 amosjeffries Exp $ * * DEBUG: section 67 String * AUTHOR: Duane Wessels @@ -34,6 +34,7 @@ */ #include "squid.h" +#include "SqString.h" #include "Store.h" void @@ -233,6 +234,14 @@ append (old.c_str(), old.len_); } +char& +SqString::operator [](unsigned int pos) +{ + assert(pos < size_ ); + + return &buf_[pos]; +} + #if DEBUGSTRINGS void SqString::stat(StoreEntry *entry) const @@ -376,7 +385,3 @@ *t = (char *) p; return (char *) word; } - -#ifndef _USE_INLINE_ -#include "SqString.cci" -#endif Index: squid3/src/SqString.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/SqString.h,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- squid3/src/SqString.h 6 May 2007 03:18:15 -0000 1.1.2.2 +++ squid3/src/SqString.h 7 May 2007 10:32:22 -0000 1.1.2.3 @@ -1,6 +1,6 @@ /* - * $Id: SqString.h,v 1.1.2.2 2007/05/06 03:18:15 amosjeffries Exp $ + * $Id: SqString.h,v 1.1.2.3 2007/05/07 10:32:22 amosjeffries Exp $ * * DEBUG: section 67 String * AUTHOR: Duane Wessels @@ -99,6 +99,8 @@ _SQUID_INLINE_ int size() const; _SQUID_INLINE_ char const * c_str() const; + char& operator [](unsigned int); + void clear(); void append(char const *buf, int len); @@ -145,9 +147,7 @@ char *buf_; }; -#ifdef _USE_INLINE_ #include "SqString.cci" -#endif #endif /* SQSTRING_H */ Index: squid3/src/SquidString.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/SquidString.h,v retrieving revision 1.8.8.4 retrieving revision 1.8.8.5 diff -u -r1.8.8.4 -r1.8.8.5 --- squid3/src/SquidString.h 6 May 2007 03:18:15 -0000 1.8.8.4 +++ squid3/src/SquidString.h 7 May 2007 10:32:22 -0000 1.8.8.5 @@ -1,9 +1,9 @@ /* - * $Id: SquidString.h,v 1.8.8.4 2007/05/06 03:18:15 amosjeffries Exp $ + * $Id: SquidString.h,v 1.8.8.5 2007/05/07 10:32:22 amosjeffries Exp $ * * DEBUG: section 67 String - * AUTHOR: Duane Wessels + * AUTHOR: Duane Wessels, Amos Jeffries * * SQUID Web Proxy Cache http://www.squid-cache.org/ * ---------------------------------------------------------- @@ -85,21 +85,16 @@ /* Overload standard C functions using the basic string API */ -//inline int strncasecmp(const string &lhs, const char *rhs, size_t len) { return strncasecmp(lhs.c_str(), rhs, len); } inline int strncasecmp(const string &lhs, const string &rhs, size_t len) { return strncasecmp(lhs.c_str(), rhs.c_str(), len); } - -//inline int strcasecmp(const string &lhs, const char *rhs) { return strcasecmp(lhs.c_str(), rhs); } inline int strcasecmp(const string &lhs, const string &rhs) { return strcasecmp(lhs.c_str(), rhs.c_str()); } -//inline int strncmp(const string &lhs, const char *rhs, size_t len) { return strncmp(lhs.c_str(), rhs, len); } inline int strncmp(const string &lhs, const string &rhs, size_t len) { return strncmp(lhs.c_str(), rhs.c_str(), len); } - -//inline int strcmp(const string &lhs, const char *rhs) { return strcmp(lhs.c_str(), rhs); } inline int strcmp(const string &lhs, const string &rhs) { return strcmp(lhs.c_str(), rhs.c_str()); } -//inline const char * strpbrk(const string &lhs, const char *rhs) { return strpbrk(lhs.c_str(), rhs); } inline const char * strpbrk(const string &lhs, const string &rhs) { return strpbrk(lhs.c_str(), rhs.c_str()); } +inline const char * strstr(const string &lhs, const string &rhs) { return strstr(lhs.c_str(), rhs.c_str()); } + inline std::ostream& operator <<(std::ostream &os, const string &s) { os << s.c_str(); return os; } #endif /* SQUID_STRING_H */ Index: squid3/src/store.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/store.cc,v retrieving revision 1.51.4.4 retrieving revision 1.51.4.5 diff -u -r1.51.4.4 -r1.51.4.5 --- squid3/src/store.cc 3 May 2007 10:05:13 -0000 1.51.4.4 +++ squid3/src/store.cc 7 May 2007 10:32:22 -0000 1.51.4.5 @@ -1,6 +1,6 @@ /* - * $Id: store.cc,v 1.51.4.4 2007/05/03 10:05:13 amosjeffries Exp $ + * $Id: store.cc,v 1.51.4.5 2007/05/07 10:32:22 amosjeffries Exp $ * * DEBUG: section 20 Storage Manager * AUTHOR: Harvest Derived @@ -693,7 +693,7 @@ rep->setHeaders(version, HTTP_OK, "Internal marker object", "x-squid-internal/vary", -1, -1, squid_curtime + 100000); vary = mem_obj->getReply()->header.getList(HDR_VARY); - if (vary.size()) { + if (!vary.empty()) { /* Again, we own this structure layout */ rep->header.putStr(HDR_VARY, vary.c_str()); vary.clear(); @@ -702,7 +702,7 @@ #if X_ACCELERATOR_VARY vary = mem_obj->getReply()->header.getList(HDR_X_ACCELERATOR_VARY); - if (vary.c_str()) { + if (!vary.empty()) { /* Again, we own this structure layout */ rep->header.putStr(HDR_X_ACCELERATOR_VARY, vary.c_str()); vary.clear(); Index: squid3/src/store_log.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/store_log.cc,v retrieving revision 1.6.2.3 retrieving revision 1.6.2.4 diff -u -r1.6.2.3 -r1.6.2.4 --- squid3/src/store_log.cc 2 May 2007 00:09:51 -0000 1.6.2.3 +++ squid3/src/store_log.cc 7 May 2007 10:32:22 -0000 1.6.2.4 @@ -1,6 +1,6 @@ /* - * $Id: store_log.cc,v 1.6.2.3 2007/05/02 00:09:51 amosjeffries Exp $ + * $Id: store_log.cc,v 1.6.2.4 2007/05/07 10:32:22 amosjeffries Exp $ * * DEBUG: section 20 Storage Manager Logging Functions * AUTHOR: Duane Wessels @@ -87,7 +87,7 @@ (int) reply->date, (int) reply->last_modified, (int) reply->expires, - reply->content_type.size() ? reply->content_type.c_str() : "unknown", + !reply->content_type.empty() ? reply->content_type.c_str() : "unknown", reply->content_length, e->contentLen(), RequestMethodStr[mem->method], Index: squid3/src/ICAP/ICAPOptions.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ICAP/ICAPOptions.cc,v retrieving revision 1.9.4.1 retrieving revision 1.9.4.2 diff -u -r1.9.4.1 -r1.9.4.2 --- squid3/src/ICAP/ICAPOptions.cc 3 May 2007 13:37:07 -0000 1.9.4.1 +++ squid3/src/ICAP/ICAPOptions.cc 7 May 2007 10:32:23 -0000 1.9.4.2 @@ -124,7 +124,7 @@ { const string s = h->getByName(fname); - if (s.size() && xisdigit(*s.c_str())) + if (!s.empty() && xisdigit(s[0])) value = atoi(s.c_str()); else value = -1; @@ -172,8 +172,8 @@ if (eLen < urlLen) { const int eOff = urlLen - eLen; // RFC 3507 examples imply that extensions come without leading '.' - if (urlPath.c_str()[eOff-1] == '.' && - strcmp(urlPath.c_str() + eOff, e->key) == 0) { + if (urlPath[eOff-1] == '.' && + strcmp(&urlPath[eOff], e->key) == 0) { debugs(93,7, "ICAPOptions url " << urlPath << " matches " << name << " extension " << e->key); return true; Index: squid3/src/ICAP/ICAPServiceRep.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ICAP/ICAPServiceRep.cc,v retrieving revision 1.7.4.4 retrieving revision 1.7.4.5 diff -u -r1.7.4.4 -r1.7.4.5 --- squid3/src/ICAP/ICAPServiceRep.cc 3 May 2007 15:03:37 -0000 1.7.4.4 +++ squid3/src/ICAP/ICAPServiceRep.cc 7 May 2007 10:32:23 -0000 1.7.4.5 @@ -91,12 +91,12 @@ debugs(3, 5, "ICAPService::parseConfigLine (line " << config_lineno << "): service is " << methodStr() << "_" << vectPointStr()); - if (uri.compare("icap://", 7) != 0) { + if (strncmp(uri, "icap://", 7) != 0) { debugs(3, 0, "ICAPService::parseConfigLine (line " << config_lineno << "): wrong uri: " << uri); return false; } - const char *s = uri.c_str() + 7; + const char *s = &uri[7]; const char *e;