From fd4d895b208937ef84a3c367f5b55e3c46375130 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 14 Sep 2011 10:17:37 +0200 Subject: * apt-pkg/contrib/configuration.cc: - fix double delete (LP: #848907) - ignore only the invalid regexp instead of all options --- apt-pkg/contrib/configuration.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc index ece05e8f6..2db191ba2 100644 --- a/apt-pkg/contrib/configuration.cc +++ b/apt-pkg/contrib/configuration.cc @@ -870,10 +870,10 @@ Configuration::MatchAgainstConfig::MatchAgainstConfig(char const * Config) { regfree(p); delete p; - clearPatterns(); - _error->Warning("Regex compilation error for '%s' in configuration option '%s'", - s->c_str(), Config); - return; + _error->Warning("Invalid regular expression '%s' in configuration " + "option '%s' will be ignored.", + s->c_str(), Config); + continue; } } if (strings.size() == 0) @@ -894,6 +894,7 @@ void Configuration::MatchAgainstConfig::clearPatterns() regfree(*p); delete *p; } + patterns.clear(); } /*}}}*/ // MatchAgainstConfig::Match - returns true if a pattern matches /*{{{*/ -- cgit v1.2.3 From 404528bd581a4d2fa3bae1834d6fde48c6153434 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 21 Sep 2011 18:42:08 +0200 Subject: convert a few for-loop char finds to proper strchr and memchr --- apt-pkg/contrib/cmndline.cc | 28 +++++++++++----------------- apt-pkg/contrib/strutl.cc | 15 +++++++-------- 2 files changed, 18 insertions(+), 25 deletions(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/cmndline.cc b/apt-pkg/contrib/cmndline.cc index 5a9944096..f7359c36e 100644 --- a/apt-pkg/contrib/cmndline.cc +++ b/apt-pkg/contrib/cmndline.cc @@ -87,9 +87,8 @@ bool CommandLine::Parse(int argc,const char **argv) Opt++; // Match up to a = against the list - const char *OptEnd = Opt; Args *A; - for (; *OptEnd != 0 && *OptEnd != '='; OptEnd++); + const char *OptEnd = strchrnul(Opt, '='); for (A = ArgList; A->end() == false && stringcasecmp(Opt,OptEnd,A->LongOpt) != 0; A++); @@ -97,9 +96,8 @@ bool CommandLine::Parse(int argc,const char **argv) bool PreceedMatch = false; if (A->end() == true) { - for (; Opt != OptEnd && *Opt != '-'; Opt++); - - if (Opt == OptEnd) + Opt = (const char*) memchr(Opt, '-', OptEnd - Opt); + if (Opt == NULL) return _error->Error(_("Command line option %s is not understood"),argv[I]); Opt++; @@ -194,9 +192,8 @@ bool CommandLine::HandleOpt(int &I,int argc,const char *argv[], // Arbitrary item specification if ((A->Flags & ArbItem) == ArbItem) { - const char *J; - for (J = Argument; *J != 0 && *J != '='; J++); - if (*J == 0) + const char *J = strchr(Argument, '='); + if (J == NULL) return _error->Error(_("Option %s: Configuration item specification must have an =."),argv[I]); // = is trailing @@ -212,8 +209,7 @@ bool CommandLine::HandleOpt(int &I,int argc,const char *argv[], return true; } - const char *I = A->ConfName; - for (; *I != 0 && *I != ' '; I++); + const char *I = strchrnul(A->ConfName, ' '); if (*I == ' ') Conf->Set(string(A->ConfName,0,I-A->ConfName),string(I+1) + Argument); else @@ -269,10 +265,9 @@ bool CommandLine::HandleOpt(int &I,int argc,const char *argv[], // Skip the leading dash const char *J = argv[I]; for (; *J != 0 && *J == '-'; J++); - - const char *JEnd = J; - for (; *JEnd != 0 && *JEnd != '-'; JEnd++); - if (*JEnd != 0) + + const char *JEnd = strchr(J, '-'); + if (JEnd != NULL) { strncpy(Buffer,J,JEnd - J); Buffer[JEnd - J] = 0; @@ -373,9 +368,8 @@ void CommandLine::SaveInConfig(unsigned int const &argc, char const * const * co { // That is possibly an option: Quote it if it includes spaces, // the benefit is that this will eliminate also most false positives - const char* c = &argv[i][j+1]; - for (; *c != '\0' && *c != ' '; ++c); - if (*c == '\0') continue; + const char* c = strchr(&argv[i][j+1], ' '); + if (c == NULL) continue; cmdline[++length] = '"'; closeQuote = true; } diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 867bb313b..8dd05b9c0 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -179,14 +179,14 @@ bool ParseQuoteWord(const char *&String,string &Res) { if (*C == '"') { - for (C++; *C != 0 && *C != '"'; C++); - if (*C == 0) + C = strchr(C + 1, '"'); + if (C == NULL) return false; } if (*C == '[') { - for (C++; *C != 0 && *C != ']'; C++); - if (*C == 0) + C = strchr(C + 1, ']'); + if (C == NULL) return false; } } @@ -904,11 +904,10 @@ bool StrToTime(const string &Val,time_t &Result) { struct tm Tm; char Month[10]; - const char *I = Val.c_str(); - + // Skip the day of the week - for (;*I != 0 && *I != ' '; I++); - + const char *I = strchr(Val.c_str(), ' '); + // Handle RFC 1123 time Month[0] = 0; if (sscanf(I," %d %3s %d %d:%d:%d GMT",&Tm.tm_mday,Month,&Tm.tm_year, -- cgit v1.2.3