ICU-2641 Return the right number when scanf is at the end of file,

and increase the code coverage of similar cases.

X-SVN-Rev: 16151
This commit is contained in:
George Rhoten 2004-08-13 08:05:43 +00:00
parent 608ca77ba5
commit 7dc0bc6c07
4 changed files with 64 additions and 56 deletions

View file

@ -40,11 +40,11 @@ typedef enum ufmt_type_info {
ufmt_float, /* float */
ufmt_double, /* double */
ufmt_uchar, /* int, cast to UChar */
ufmt_ustring, /* UChar* */
ufmt_ustring /* UChar* */
/*ufmt_wchar,*/ /* wchar_t */
/*ufmt_wstring,*/ /* wchar_t* */
/*ufmt_date,*/ /* Date */
ufmt_last
/*ufmt_last*/
} ufmt_type_info;
/**

View file

@ -1349,36 +1349,36 @@ u_printf_parse(const u_printf_stream_handler *streamHandler,
if (handlerNum < UPRINTF_NUM_FMT_HANDLERS) {
/* query the info function for argument information */
argType = g_u_printf_infos[ handlerNum ].info;
if(argType > ufmt_simple_percent) {
switch(argType) {
case ufmt_count:
/* set the spec's width to the # of chars written */
info->fWidth = *written;
/* fall through to set the pointer */
case ufmt_string:
case ufmt_ustring:
case ufmt_pointer:
args.ptrValue = va_arg(ap, void*);
break;
case ufmt_char:
case ufmt_uchar:
case ufmt_int:
if (info->fIsLongLong) {
args.int64Value = va_arg(ap, int64_t);
}
else {
args.int64Value = va_arg(ap, int32_t);
}
break;
case ufmt_float:
args.floatValue = (float) va_arg(ap, double);
break;
case ufmt_double:
args.doubleValue = va_arg(ap, double);
break;
default:
break; /* Should never get here */
switch(argType) {
case ufmt_count:
/* set the spec's width to the # of chars written */
info->fWidth = *written;
/* fall through to set the pointer */
case ufmt_string:
case ufmt_ustring:
case ufmt_pointer:
args.ptrValue = va_arg(ap, void*);
break;
case ufmt_char:
case ufmt_uchar:
case ufmt_int:
if (info->fIsLongLong) {
args.int64Value = va_arg(ap, int64_t);
}
else {
args.int64Value = va_arg(ap, int32_t);
}
break;
case ufmt_float:
args.floatValue = (float) va_arg(ap, double);
break;
case ufmt_double:
args.doubleValue = va_arg(ap, double);
break;
default:
/* else args is ignored */
args.ptrValue = NULL;
break;
}
/* call the handler function */

View file

@ -1253,35 +1253,38 @@ u_scanf_parse(UFILE *f,
handlerNum = (uint16_t)(spec.fInfo.fSpec - USCANF_BASE_FMT_HANDLERS);
if (handlerNum < USCANF_NUM_FMT_HANDLERS) {
/* skip the argument, if necessary */
if(spec.fInfo.fSkipArg) {
/* query the info function for argument information */
info = g_u_scanf_infos[ handlerNum ].info;
if (info != ufmt_count && u_feof(f)) {
break;
}
else if(spec.fInfo.fSkipArg) {
args.ptrValue = NULL;
}
else {
/* query the info function for argument information */
info = g_u_scanf_infos[ handlerNum ].info;
if(info > ufmt_simple_percent) {
switch(info) {
switch(info) {
case ufmt_count:
/* set the spec's width to the # of items converted */
spec.fInfo.fWidth = cpConsumed;
/* fall through to next case */
case ufmt_char:
case ufmt_uchar:
case ufmt_int:
case ufmt_string:
case ufmt_ustring:
case ufmt_pointer:
case ufmt_float:
case ufmt_double:
args.ptrValue = va_arg(ap, void*);
break;
case ufmt_count:
/* set the spec's width to the # of items converted */
spec.fInfo.fWidth = cpConsumed;
/* fall through to next case */
case ufmt_char:
case ufmt_uchar:
case ufmt_int:
case ufmt_string:
case ufmt_ustring:
case ufmt_pointer:
case ufmt_float:
case ufmt_double:
args.ptrValue = va_arg(ap, void*);
break;
default:
break; /* Should never get here */
}
default:
/* else args is ignored */
args.ptrValue = NULL;
break;
}
}
/* call the handler function */
handler = g_u_scanf_infos[ handlerNum ].handler;
if(handler != 0) {
@ -1292,8 +1295,10 @@ u_scanf_parse(UFILE *f,
cpConsumed += (*handler)(f, &spec.fInfo, &args, alias, &count, &argConsumed);
/* if the handler encountered an error condition, break */
if(argConsumed < 0)
if(argConsumed < 0) {
converted = -converted;
break;
}
/* add to the # of items converted */
converted += argConsumed;

View file

@ -295,7 +295,10 @@ static void TestFileFromICU(UFILE *myFile) {
log_err("u_fgets got \"%s\"\n", myString);
}
if (!u_feof(myFile)) {
log_err("Got feof while reading the end of the file.\n");
log_err("Did not get feof while reading the end of the file.\n");
}
if (u_fscanf(myFile, "%S\n", myUString) != 0) {
log_err("u_fscanf read data while reading the end of the file.\n");
}
u_fclose(myFile);