mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 06:25:30 +00:00
ICU-5889 Fix some logic errors uncovered by BEAM.
X-SVN-Rev: 22558
This commit is contained in:
parent
70f1c626eb
commit
967b65a458
14 changed files with 51 additions and 42 deletions
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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<DEFAULT_PADDING_LENGTH) {
|
||||
fprintf(stderr, "%s: empty input file \"%s\"\n", pname, argv[1]);
|
||||
rc=2;
|
||||
goto done;
|
||||
|
@ -182,7 +183,7 @@ main(int argc, char *argv[]) {
|
|||
* because the last item may be resorted into the middle and then needs
|
||||
* additional padding bytes
|
||||
*/
|
||||
data=(char *)malloc(length+15);
|
||||
data=(char *)malloc(length+DEFAULT_PADDING_LENGTH);
|
||||
if(data==NULL) {
|
||||
fprintf(stderr, "%s: error allocating memory for \"%s\"\n", pname, argv[1]);
|
||||
rc=2;
|
||||
|
@ -190,7 +191,7 @@ main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
/* set the last 15 bytes to the usual padding byte, see udata_swapPackage() */
|
||||
uprv_memset(data+length-15, 0xaa, 15);
|
||||
uprv_memset(data+length-DEFAULT_PADDING_LENGTH, 0xaa, DEFAULT_PADDING_LENGTH);
|
||||
|
||||
if(length!=(int32_t)fread(data, 1, length, in)) {
|
||||
fprintf(stderr, "%s: error reading \"%s\"\n", pname, argv[1]);
|
||||
|
@ -519,7 +520,7 @@ udata_swapPackage(const char *inFilename, const char *outFilename,
|
|||
*/
|
||||
if(inData==outData) {
|
||||
/* +15: prepare for extra padding of a newly-last item */
|
||||
table=(ToCEntry *)uprv_malloc(itemCount*sizeof(ToCEntry)+length+15);
|
||||
table=(ToCEntry *)uprv_malloc(itemCount*sizeof(ToCEntry)+length+DEFAULT_PADDING_LENGTH);
|
||||
if(table!=NULL) {
|
||||
outBytes=(uint8_t *)(table+itemCount);
|
||||
|
||||
|
@ -533,7 +534,7 @@ udata_swapPackage(const char *inFilename, const char *outFilename,
|
|||
if(table==NULL) {
|
||||
udata_printError(ds, "udata_swapPackage(): out of memory allocating %d bytes\n",
|
||||
inData==outData ?
|
||||
itemCount*sizeof(ToCEntry)+length+15 :
|
||||
itemCount*sizeof(ToCEntry)+length+DEFAULT_PADDING_LENGTH :
|
||||
itemCount*sizeof(ToCEntry));
|
||||
*pErrorCode=U_MEMORY_ALLOCATION_ERROR;
|
||||
return 0;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**************************************************************************
|
||||
*
|
||||
* Copyright (C) 2000-2006, International Business Machines
|
||||
* Copyright (C) 2000-2007, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
***************************************************************************
|
||||
|
@ -223,7 +223,7 @@ CharList *pkg_appendUniqueDirToList(CharList *l, CharList** end, const char *str
|
|||
if(!rPtr) {
|
||||
return l; /* no dir path */
|
||||
}
|
||||
if((rPtr-strAlias) > (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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue