i get this error and can’t fix, i’m noob yet,if someone can help me i’ll thank you
this code come from xmplayer of libxenon (for jtag xbox)
(i try search similar error, but i can’t find what’s wrong)
int FileSortCallback(const void *f1, const void *f2) {
/* Special case for implicit directories */
if (((BROWSERENTRY *) f1)->filename[0] == '.' || ((BROWSERENTRY *) f2)->filename[0] == '.') {
if (strcmp(((BROWSERENTRY *) f1)->filename, ".") == 0) {
return -1;
}
if (strcmp(((BROWSERENTRY *) f2)->filename, ".") == 0) {
return 1;
}
if (strcmp(((BROWSERENTRY *) f1)->filename, "..") == 0) {
return -1;
}
if (strcmp(((BROWSERENTRY *) f2)->filename, "..") == 0) {
return 1;
}
}
/* If one is a file and one is a directory the directory is first. */
if (((BROWSERENTRY *) f1)->isdir && !(((BROWSERENTRY *) f2)->isdir)) return -1;
if (!(((BROWSERENTRY *) f1)->isdir) && ((BROWSERENTRY *) f2)->isdir) return 1;
//Ascending Name
if (XMPlayerCfg.sort_order == 0) {
return stricmp(((BROWSERENTRY *) f1)->filename, ((BROWSERENTRY *) f2)->filename);
}
//Descending Name
else if (XMPlayerCfg.sort_order == 1) {
return stricmp(((BROWSERENTRY *) f2)->filename, ((BROWSERENTRY *) f1)->filename);
}
//Date Ascending
else if (XMPlayerCfg.sort_order == 2) {
if ( ((BROWSERENTRY *) f2)->date == ((BROWSERENTRY *) f1)->date) { //if date is the same order by filename
return stricmp(((BROWSERENTRY *) f2)->filename, ((BROWSERENTRY *) f1)->filename);
} else {
return ((BROWSERENTRY *) f1)->date - ((BROWSERENTRY *) f2)->date;
}
}
//Date Descending
else if (XMPlayerCfg.sort_order == 3) {
if ( ((BROWSERENTRY *) f2)->date == ((BROWSERENTRY *) f1)->date) { //if date is the same order by filename
return stricmp(((BROWSERENTRY *) f1)->filename, ((BROWSERENTRY *) f2)->filename);
} else {
return ((BROWSERENTRY *) f2)->date - ((BROWSERENTRY *) f1)->date;
}
}
}
The compiler analyzes your code, and sees that a return statement will be executed for all values of
sort_orderbetween0and5, inclusive. However, if thesort_orderis negative or more than5, the code would reach the end of the function without a return statement; that is why the compiler issues a warning.Note that it may not be possible for
sort_orderto be set to a negative number or a number over5because of constraints in other parts of your code. However, the compiler does not know any of that, so it thinks thatsort_ordercould have any value.To fix this problem, add an unconditional return statement at the end.