diff --git a/icu4c/source/common/rbbiscan.cpp b/icu4c/source/common/rbbiscan.cpp index f66a019f873..2d5c5ec1f02 100644 --- a/icu4c/source/common/rbbiscan.cpp +++ b/icu4c/source/common/rbbiscan.cpp @@ -192,13 +192,13 @@ RBBIRuleScanner::~RBBIRuleScanner() { // definitions problems. I'm sure that there's a better way. // //---------------------------------------------------------------------------------------- -UBool RBBIRuleScanner::doParseActions(EParseAction action) +UBool RBBIRuleScanner::doParseActions(int32_t action) { RBBINode *n = NULL; UBool returnVal = TRUE; - switch ((RBBI_RuleParseAction)action) { + switch (action) { case doExprStart: pushNewNode(RBBINode::opStart); @@ -994,7 +994,7 @@ void RBBIRuleScanner::parse() { // We've found the row of the state table that matches the current input // character from the rules string. // Perform any action specified by this row in the state table. - if (doParseActions((EParseAction)tableEl->fAction) == FALSE) { + if (doParseActions((int32_t)tableEl->fAction) == FALSE) { // Break out of the state machine loop if the // the action signalled some kind of error, or // the action was to exit, occurs on normal end-of-rules-input. diff --git a/icu4c/source/common/rbbiscan.h b/icu4c/source/common/rbbiscan.h index 89748318eee..cd0bf94a4fb 100644 --- a/icu4c/source/common/rbbiscan.h +++ b/icu4c/source/common/rbbiscan.h @@ -1,7 +1,7 @@ // // rbbiscan.h // -// Copyright (C) 2002-2005, International Business Machines Corporation and others. +// Copyright (C) 2002-2007, International Business Machines Corporation and others. // All Rights Reserved. // // This file contains declarations for class RBBIRuleScanner @@ -46,10 +46,6 @@ static const int kStackSize = 100; // The size of the state sta // to the depth of parentheses nesting // that is allowed in the rules. -enum EParseAction {dummy01, dummy02}; // Placeholder enum for the specifier for - // actions that are specified in the - // rule parsing state table. - class RBBIRuleScanner : public UMemory { public: @@ -81,7 +77,7 @@ public: static UnicodeString stripRules(const UnicodeString &rules); private: - UBool doParseActions(EParseAction a); + UBool doParseActions(int32_t a); void error(UErrorCode e); // error reporting convenience function. void fixOpStack(RBBINode::OpPrecedence p); // a character. diff --git a/icu4c/source/common/triedict.cpp b/icu4c/source/common/triedict.cpp index 4983e9cd2d8..db1c8ebdcc0 100644 --- a/icu4c/source/common/triedict.cpp +++ b/icu4c/source/common/triedict.cpp @@ -1,7 +1,7 @@ /** ******************************************************************************* - * Copyright (C) 2006, International Business Machines Corporation and others. * - * All Rights Reserved. * + * Copyright (C) 2006-2007, International Business Machines Corporation * + * and others. All Rights Reserved. * ******************************************************************************* */ @@ -820,7 +820,7 @@ compactOneNode(const TernaryNode *node, UBool parentEndsWord, UStack &nodes, UEr if (vResult == NULL) { status = U_MEMORY_ALLOCATION_ERROR; } - if (U_SUCCESS(status)) { + else if (U_SUCCESS(status)) { UBool endsWord = FALSE; // Take up nodes until we end a word, or hit a node with < or > links do { diff --git a/icu4c/source/common/usprep.cpp b/icu4c/source/common/usprep.cpp index 00f4788d884..12d51be3caa 100644 --- a/icu4c/source/common/usprep.cpp +++ b/icu4c/source/common/usprep.cpp @@ -1,7 +1,7 @@ /* ******************************************************************************* * - * Copyright (C) 2003-2006, International Business Machines + * Copyright (C) 2003-2007, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -445,7 +445,7 @@ uprv_syntaxError(const UChar* rules, parseError->line = 0 ; // we are not using line numbers // for pre-context - int32_t start = (pos <=U_PARSE_CONTEXT_LEN)? 0 : (pos - (U_PARSE_CONTEXT_LEN-1)); + int32_t start = (pos < U_PARSE_CONTEXT_LEN)? 0 : (pos - (U_PARSE_CONTEXT_LEN-1)); int32_t limit = pos; u_memcpy(parseError->preContext,rules+start,limit-start); diff --git a/icu4c/source/i18n/format.cpp b/icu4c/source/i18n/format.cpp index e93642c6ade..883a41d575e 100644 --- a/icu4c/source/i18n/format.cpp +++ b/icu4c/source/i18n/format.cpp @@ -1,6 +1,6 @@ /* ******************************************************************************* -* Copyright (C) 1997-2004, International Business Machines Corporation and * +* Copyright (C) 1997-2007, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* * @@ -152,7 +152,7 @@ void Format::syntaxError(const UnicodeString& pattern, parseError.line=0; // we are not using line number // for pre-context - int32_t start = (pos <=U_PARSE_CONTEXT_LEN)? 0 : (pos - (U_PARSE_CONTEXT_LEN-1 + int32_t start = (pos < U_PARSE_CONTEXT_LEN)? 0 : (pos - (U_PARSE_CONTEXT_LEN-1 /* subtract 1 so that we have room for null*/)); int32_t stop = pos; pattern.extract(start,stop-start,parseError.preContext,0); diff --git a/icu4c/source/i18n/ucol.cpp b/icu4c/source/i18n/ucol.cpp index ff9d42e99da..96726a2559a 100644 --- a/icu4c/source/i18n/ucol.cpp +++ b/icu4c/source/i18n/ucol.cpp @@ -5529,6 +5529,8 @@ ucol_nextSortKeyPart(const UCollator *coll, count<0 || (count>0 && dest==NULL) ) { *status=U_ILLEGAL_ARGUMENT_ERROR; + UTRACE_EXIT_STATUS(status); + return 0; } UTRACE_DATA6(UTRACE_VERBOSE, "coll=%p, iter=%p, state=%d %d, dest=%p, count=%d", diff --git a/icu4c/source/i18n/ucol_tok.cpp b/icu4c/source/i18n/ucol_tok.cpp index 83528582229..8a8ea4455ae 100644 --- a/icu4c/source/i18n/ucol_tok.cpp +++ b/icu4c/source/i18n/ucol_tok.cpp @@ -172,7 +172,7 @@ void syntaxError(const UChar* rules, parseError->line = 0 ; /* we are not using line numbers */ // for pre-context - int32_t start = (pos <=U_PARSE_CONTEXT_LEN)? 0 : (pos - (U_PARSE_CONTEXT_LEN-1)); + int32_t start = (pos < U_PARSE_CONTEXT_LEN)? 0 : (pos - (U_PARSE_CONTEXT_LEN-1)); int32_t stop = pos; u_memcpy(parseError->preContext,rules+start,stop-start); diff --git a/icu4c/source/io/locbund.c b/icu4c/source/io/locbund.c index fd4935842a3..1859999b158 100644 --- a/icu4c/source/io/locbund.c +++ b/icu4c/source/io/locbund.c @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 1998-2006, International Business Machines +* Copyright (C) 1998-2007, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -162,7 +162,7 @@ UNumberFormat* u_locbund_getNumberFormat(ULocaleBundle *bundle, UNumberFormatStyle style) { UNumberFormat *formatAlias = NULL; - if (style >= UNUM_IGNORE) { + if (style > UNUM_IGNORE) { formatAlias = bundle->fNumberFormat[style-1]; if (formatAlias == NULL) { if (bundle->isInvariantLocale) { diff --git a/icu4c/source/tools/ctestfw/uperf.cpp b/icu4c/source/tools/ctestfw/uperf.cpp index 05a8839e677..5b2dbe667b0 100644 --- a/icu4c/source/tools/ctestfw/uperf.cpp +++ b/icu4c/source/tools/ctestfw/uperf.cpp @@ -439,12 +439,16 @@ UBool UPerfTest::runTestLoop( char* testname, char* par ) } if(verbose && U_SUCCESS(status)) { double avg_t = sum_t/passes; - if(events == -1) { + if (loops == 0 || ops == 0) { + fprintf(stderr, "%s did not run\n", name); + } + else if(events == -1) { fprintf(stdout, "%%= %s avg: %.4g loops: %i avg/op: %.4g ns\n", name, avg_t, (int)loops, (avg_t*1E9)/(loops*ops)); fprintf(stdout, "_= %s min: %.4g loops: %i min/op: %.4g ns\n", name, min_t, (int)loops, (min_t*1E9)/(loops*ops)); - } else { + } + else { fprintf(stdout, "%%= %s avg: %.4g loops: %i avg/op: %.4g ns avg/event: %.4g ns\n", name, avg_t, (int)loops, (avg_t*1E9)/(loops*ops), (avg_t*1E9)/(loops*events)); fprintf(stdout, "_= %s min: %.4g loops: %i min/op: %.4g ns min/event: %.4g ns\n", diff --git a/icu4c/source/tools/gencase/store.c b/icu4c/source/tools/gencase/store.c index c4d241eed45..90d3abf8d71 100644 --- a/icu4c/source/tools/gencase/store.c +++ b/icu4c/source/tools/gencase/store.c @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2004-2005, International Business Machines +* Copyright (C) 2004-2007, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -266,7 +266,7 @@ addUnfolding(UChar32 c, const UChar *s, int32_t length) { (long)length, UGENCASE_UNFOLD_STRING_WIDTH); exit(U_INTERNAL_PROGRAM_ERROR); } - if(unfoldTop>=LENGTHOF(unfold)) { + if(unfoldTop >= (LENGTHOF(unfold) - UGENCASE_UNFOLD_STRING_WIDTH)) { fprintf(stderr, "gencase error: too many multi-character case foldings\n"); exit(U_BUFFER_OVERFLOW_ERROR); } diff --git a/icu4c/source/tools/genuca/genuca.cpp b/icu4c/source/tools/genuca/genuca.cpp index 8a0f87180c9..8fb29b4aa2a 100644 --- a/icu4c/source/tools/genuca/genuca.cpp +++ b/icu4c/source/tools/genuca/genuca.cpp @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2000-2006, International Business Machines +* Copyright (C) 2000-2007, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -473,8 +473,8 @@ UCAElements *readAnElement(FILE *data, tempUCATable *t, UCAConstants *consts, UE // Directives. if(buffer[0] == '[') { uint32_t cnt = 0; - struct { - char name[256]; + static const struct { + char name[128]; uint32_t *what; ActionType what_to_do; } vt[] = { {"[first tertiary ignorable", consts->UCA_FIRST_TERTIARY_IGNORABLE, READCE}, @@ -682,13 +682,19 @@ UCAElements *readAnElement(FILE *data, tempUCATable *t, UCAConstants *consts, UE element->isThai = UCOL_ISTHAIPREVOWEL(element->cPoints[0]); #endif // we don't want any strange stuff after useful data! - while(pointer < commentStart) { - if(*pointer != ' ' && *pointer != '\t') - { - *status=U_INVALID_FORMAT_ERROR; - break; + if (pointer == NULL) { + /* huh? Did we get ']' without the '['? Pair your brackets! */ + *status=U_INVALID_FORMAT_ERROR; + } + else { + while(pointer < commentStart) { + if(*pointer != ' ' && *pointer != '\t') + { + *status=U_INVALID_FORMAT_ERROR; + break; + } + pointer++; } - pointer++; } if(U_FAILURE(*status)) { diff --git a/icu4c/source/tools/icuswap/icuswap.cpp b/icu4c/source/tools/icuswap/icuswap.cpp index 2fb331995be..a5295df651f 100644 --- a/icu4c/source/tools/icuswap/icuswap.cpp +++ b/icu4c/source/tools/icuswap/icuswap.cpp @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2003-2006, International Business Machines +* Copyright (C) 2003-2007, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -42,6 +42,7 @@ /* definitions */ #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) +#define DEFAULT_PADDING_LENGTH 15 static UOption options[]={ UOPTION_HELP_H, @@ -170,7 +171,7 @@ main(int argc, char *argv[]) { } length=fileSize(in); - if(length<=0) { + if(length (sizeof(aBuf)/sizeof(aBuf[0]))) { + if((rPtr-strAlias) >= (sizeof(aBuf)/sizeof(aBuf[0]))) { fprintf(stderr, "## ERR: Path too long [%d chars]: %s\n", (int)sizeof(aBuf), strAlias); return l; } diff --git a/icu4c/source/tools/toolutil/writesrc.c b/icu4c/source/tools/toolutil/writesrc.c index a53bb4b2d86..28303c733e5 100644 --- a/icu4c/source/tools/toolutil/writesrc.c +++ b/icu4c/source/tools/toolutil/writesrc.c @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2005, International Business Machines +* Copyright (C) 2005-2007, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -72,7 +72,7 @@ usrc_create(const char *path, const char *filename) { fprintf( stderr, "usrc_create(%s, %s): unable to create file\n", - path!=NULL ? path : NULL, filename); + path!=NULL ? path : "", filename); } return f; }