 |
|
 |
MAEC TOOL NEWS:
MAECT-M3T-NC308WA_1-020616D
A Note on C Compilers M3T-NC308WA, M3T-NC30WA, and M3T-NC79WA
|
Please take note of the following problem in using C compilers (with an assembler and integrated development environment) M3T-NC308WA, M3T-NC30WA, and M3T-NC79WA:
- On using standard function libraries scanf, fscanf, and sscanf
- Products and Versions Concerned
- C compiler for the M32C/80 and M16C/80 series MCUs:
- M3T-NC308WA V.3.00 Release 1 -- V.3.10 Release 3
- C compiler for the M16C/60, M16C/30, M16C/20, and M16C/10 series MCUs:
- M3T-NC30WA V.4.00 Release 1 -- V.4.00 Release 2
- C compiler for the 79xx series MCUs:
- M3T-NC79WA V.4.00 Release 1 -- V.4.10 Release 1
- Problem
In a scanf, fscanf, or sscanf function, conversion of an input character string that contains '0's by using the conversion specifier 'x' may not correctly be performed.
- 2.1 Conditions
- This problem occurs if the following four conditions are satisfied:
- (1) An input string contains a '0' or '0's.
- (2) A '0' in the string in (1) is converted using the conversion specifier 'x'.
- (3) The '0' in (2) is either of the following:
- (a) The '0' in (2) is at head of the input character string.
- (b) The character placed immediately before the '0' in (2) is not any of '0'--'9', 'a'--'f', and 'A'--'F'.
- (4) The character placed immediately after the '0' in (2) is not any of '0'--'9', 'a'--'f', 'A'--'F', 'x', 'X', and '\0'.
- 2.2 Example
[C source program]
-----------------------------------------------------------------------
#include <stdio.h>
void main(void);
void func(void);
void main(void)
{
func();
}
void func(void)
{
int input = 1234;
int returnVal = 0;
const char* pStr = "0"; // Conditions (1), (3)(a), and (4)
returnVal = sscanf(pStr, "%x", &input); // Condition (2)
}
-----------------------------------------------------------------------
- [Execution results of the above program]
- returnVal = -1
- input = 1234
- The correct results are returnVal = 1 and input = 0.
- Workaround
Modify the library source file scan.c of each product as described in 3.1, 3.2, or 3.3 below and then re-create the library.
For re-creation of the library, see "Modifying Standard Library" in the User's Manual of each product.
- 3.1 For M3T-NC308WA V.3.00 Release 1 -- V.3.10 Release 3
- Modify the several lines beginning at line 295 in the scan.c file saved in the src308\lib subdirectory under the M3T-NC308WA-installed directory as follows:
[Original]
-----------------------------------------------------------------------
hex:
if ( !width || !isxdigit( c ) )
break;
data = 0L;
if(c=='0'){
c=(*f_in)();
if(c=='x'||c=='X'){
if(!isxdigit(c=*f_in)()))
goto next;
}else if(!isxdigit(c))
break;
}
-----------------------------------------------------------------------
[Modified]
-----------------------------------------------------------------------
hex:
if ( !width || !isxdigit( c ) )
break;
data = 0L;
if(c=='0'){
c=(*f_in)();
width--; // Add width--;
if(c=='x'||c=='X'){
if(!isxdigit(c=*f_in)()))
goto next;
}else if(!isxdigit(c)){ // Enclose break; with the
status = TRUE; // curly braces { } and
break; // add status = TRUE; in front
} // of break;.
}
-----------------------------------------------------------------------
- 3.2 For M3T-NC30WA V.4.00 Release 1 -- V.4.00 Release 2
- Modify the several lines beginning at line 294 in the scan.c file saved in the src30\lib subdirectory under the M3T-NC30WA-installed directory as follows:
[Original]
-----------------------------------------------------------------------
hex:
if ( !width || !isxdigit( c ) )
break;
data =0L;
if(c=='0'){
c=(*f_in)();
if(c=='x'||c=='X'){
if(!isxdigit(c=(*f_in)()))
goto next;
}else if(!isxdigit(c))
break;
}
-----------------------------------------------------------------------
[Modified]
-----------------------------------------------------------------------
hex:
if ( !width || !isxdigit( c ) )
break;
data = 0L;
if(c=='0'){
c=(*f_in)();
width--; // Add width--;
if(c=='x'||c=='X'){
if(!isxdigit(c=*f_in)()))
goto next;
}else if(!isxdigit(c)){ // Enclose break; with the
status = TRUE; // curly braces { } and
break; // add status = TRUE; in front
} // of break;.
}
-----------------------------------------------------------------------
- 3.3 For M3T-NC79WA V.4.00 Release 1 -- V.4.10 Release 1
- Modify the several lines beginning at line 318 in the scan.c file saved in the src79\lib subdirectory under the M3T-NC79WA-installed directory as follows:
[Original]
-----------------------------------------------------------------------
hex:
data = 0L;
if ( !width || !isxdigit( c ) )
break;
if(c=='0'){
c=(*f_in)();
if(c=='x'||c=='X'){
if(!isxdigit(c=(*f_in)()))
goto next;
}
else if(!isxdigit(c))
break;
}
-----------------------------------------------------------------------
[Modified]
-----------------------------------------------------------------------
hex:
data = 0L;
if ( !width || !isxdigit( c ) )
break;
if(c=='0'){
c=(*f_in)();
width--; // Add width--;
if(c=='x'||c=='X'){
if(!isxdigit(c=*f_in)()))
goto next;
}
else if(!isxdigit(c)){ // Enclose break; with the
status = TRUE; // curly braces { } and
break; // add status = TRUE; in front
} // of break;.
}
-----------------------------------------------------------------------
- Schedule of Fixing the Problem
- For M3T-NC308WA and M3T-NC79WA, we plan to fix this problem in our next releases.
- For M3T-NC30WA, please use M3T-NC30WA V.5.00 Release 1 or later.
|
 |