ICU-5732 Clean up new code. Fix uninitialized memory errors, unused variables, unfriendly crashes and so forth.

X-SVN-Rev: 22314
This commit is contained in:
George Rhoten 2007-08-08 02:41:25 +00:00
parent c9f5e38fb9
commit 0d715edd6f
3 changed files with 23 additions and 30 deletions

View file

@ -21,6 +21,7 @@
#include "unicode/ubidi.h"
#include "ubidi_props.h"
#include "ubidiimp.h"
#include "uassert.h"
/*
* General implementation notes:
@ -114,14 +115,6 @@ static const Flags flagO[2]={ DIRPROP_FLAG(LRO), DIRPROP_FLAG(RLO) };
/* UBiDi object management -------------------------------------------------- */
static void
crash()
{
char ** pc;
pc = NULL;
*pc = "make it crash!";
}
U_CAPI UBiDi * U_EXPORT2
ubidi_open(void)
{
@ -1380,7 +1373,7 @@ processPropertySeq(UBiDi *pBiDi, LevState *pLevState, uint8_t _prop,
break;
default: /* we should never get here */
crash();
U_ASSERT(FALSE);
break;
}
}
@ -1494,7 +1487,7 @@ resolveImplicitLevels(UBiDi *pBiDi,
start2=i;
break;
default: /* we should never get here */
crash();
U_ASSERT(FALSE);
break;
}
}
@ -1898,10 +1891,6 @@ ubidi_setPara(UBiDi *pBiDi, const UChar *text, int32_t length,
case UBIDI_REORDER_GROUP_NUMBERS_WITH_R:
pBiDi->pImpTabPair=&impTab_GROUP_NUMBERS_WITH_R;
break;
case UBIDI_REORDER_RUNS_ONLY:
/* we should never get here */
crash();
break;
case UBIDI_REORDER_INVERSE_NUMBERS_AS_L:
pBiDi->pImpTabPair=&impTab_INVERSE_NUMBERS_AS_L;
break;
@ -1919,6 +1908,11 @@ ubidi_setPara(UBiDi *pBiDi, const UChar *text, int32_t length,
pBiDi->pImpTabPair=&impTab_INVERSE_FOR_NUMBERS_SPECIAL;
}
break;
case UBIDI_REORDER_RUNS_ONLY:
case UBIDI_REORDER_COUNT:
/* we should never get here */
U_ASSERT(FALSE);
break;
}
/*
* If there are no external levels specified and there

View file

@ -308,7 +308,7 @@ U_CAPI void U_EXPORT2
ubidi_getLogicalRun(const UBiDi *pBiDi, int32_t logicalStart,
int32_t *pLogicalLimit, UBiDiLevel *pLevel) {
UErrorCode errorCode;
int32_t length, runCount, visualStart, logicalLimit, logicalFirst, i;
int32_t runCount, visualStart, logicalLimit, logicalFirst, i;
Run iRun;
errorCode=U_ZERO_ERROR;
@ -1159,7 +1159,6 @@ ubidi_getLogicalMap(UBiDi *pBiDi, int32_t *indexMap, UErrorCode *pErrorCode) {
markFound++;
}
if(markFound>0) {
int32_t logicalLimit;
logicalStart=GET_INDEX(runs[i].logicalStart);
logicalLimit=logicalStart+length;
for(j=logicalStart; j<logicalLimit; j++) {

View file

@ -102,6 +102,8 @@ static void printUnicode(const UChar *s, int32_t length, const UBiDiLevel *level
/* regression tests ---------------------------------------------------------*/
void addComplexTest(TestNode** root);
void
addComplexTest(TestNode** root) {
addTest(root, testCharFromDirProp, "complex/bidi/TestCharFromDirProp");
@ -373,7 +375,7 @@ static char * formatLevels(UBiDi *bidi, char *buffer) {
}
for (i=0; i<len; i++) {
k = gotLevels[i];
if (k >= sizeof columns)
if (k >= sizeof(columns))
c = '+';
else
c = columns[k];
@ -382,7 +384,7 @@ static char * formatLevels(UBiDi *bidi, char *buffer) {
buffer[len] = '\0';
return buffer;
}
static char *reorderingModeNames[] = {
static const char *reorderingModeNames[] = {
"UBIDI_REORDER_DEFAULT",
"UBIDI_REORDER_NUMBERS_SPECIAL",
"UBIDI_REORDER_GROUP_NUMBERS_WITH_R",
@ -429,7 +431,7 @@ static void printCaseInfo(UBiDi *bidi, const char *src, const char *dst)
lev = levels[i];
if (lev < 0) {
levelChars[i] = '-';
} else if (lev < sizeof columns) {
} else if (lev < sizeof(columns)) {
levelChars[i] = columns[lev];
} else {
levelChars[i] = '+';
@ -1137,14 +1139,13 @@ static void doMisc(void) {
/* Miscellaneous tests to exercize less popular code paths */
UBiDi *bidi, *bidiLine;
UChar src[MAXLEN], dest[MAXLEN];
int32_t srcLen, destLen, runStart, runCount, i;
int32_t srcLen, destLen, runCount, i;
UBiDiLevel level;
const UBiDiLevel *levels;
UBiDiDirection dir;
int32_t map[MAXLEN];
UErrorCode errorCode=U_ZERO_ERROR;
static uint32_t srcMap[6] = {0,1,-1,5,4};
static uint32_t dstMap[6] = {0,1,-1,-1,4,3};
static const int32_t srcMap[6] = {0,1,-1,5,4};
static const int32_t dstMap[6] = {0,1,-1,-1,4,3};
bidi = ubidi_openSized(120, 66, &errorCode);
if (bidi == NULL) {
@ -1264,7 +1265,7 @@ static void doMisc(void) {
RETURN_IF_BAD_ERRCODE("#10#");
ubidi_invertMap(srcMap, map, 5);
if (memcmp(dstMap, map, sizeof dstMap)) {
if (memcmp(dstMap, map, sizeof(dstMap))) {
log_err("\nUnexpected inverted Map, got ");
for (i = 0; i < 6; i++) {
log_err("%d ", map[i]);
@ -1424,11 +1425,9 @@ static void
testFailureRecovery(void) {
UErrorCode errorCode;
UBiDi *bidi, *bidiLine;
UChar src[MAXLEN], dest[MAXLEN];
int32_t srcLen, destLen, runStart, runCount, i;
UChar src[MAXLEN];
int32_t srcLen;
UBiDiLevel level;
const UBiDiLevel *levels;
UBiDiDirection dir;
UBiDiReorderingMode rm;
static UBiDiLevel myLevels[3] = {6,5,4};
@ -2069,7 +2068,7 @@ static void _testManyAddedPoints(void) {
}
ubidi_setReorderingMode(bidi, UBIDI_REORDER_INVERSE_LIKE_DIRECT);
ubidi_setReorderingOptions(bidi, UBIDI_OPTION_INSERT_MARKS);
ubidi_setPara(bidi, text, sizeof text, UBIDI_LTR, NULL, &errorCode);
ubidi_setPara(bidi, text, sizeof(text)/sizeof(text[0]), UBIDI_LTR, NULL, &errorCode);
destLen = ubidi_writeReordered(bidi, dest, MAXLEN, 0, &errorCode);
for (i = 0; i < 120; i+=4) {
expected[i] = 'a';
@ -2082,6 +2081,7 @@ static void _testManyAddedPoints(void) {
"expected '%s', got '%s'\n",
aescstrdup(expected, 120), aescstrdup(dest, destLen));
}
ubidi_close(bidi);
}
static void _testMisc(void) {
@ -3708,7 +3708,7 @@ static char * formatMap(const int32_t * map, int len, char * buffer)
k = map[i];
if (k < 0)
c = '-';
else if (k >= sizeof columns)
else if (k >= sizeof(columns))
c = '+';
else
c = columns[k];