- we should end the countrycode string with '\0' before feeding it to strtol
- fgets retval should be tested with != NULL, not with > 0 (it returns a ptr, not the len)
pmo-trunk-r4029
parse_mcc_mapping_line (const char* line, char** country)
{
int i, j;
- char mcc[3]; /* the mcc code, always 3 bytes*/
+ char mcc[4]; /* the mcc code, always 3 bytes*/
static char my_country[128];
if (!line) {
mcc[0] = line[0];
mcc[1] = line[1];
mcc[2] = line[2];
+ mcc[3] = '\0';
*country = my_country;
return;
}
- while (fgets (line, MAX_LINE_LEN, file) > 0) {
+ while (fgets (line, MAX_LINE_LEN, file) != NULL) {
int mcc;
char *country = NULL;