Skip to content

Commit

Permalink
Resolve compiler warning on ARM
Browse files Browse the repository at this point in the history
  • Loading branch information
vacantron committed Dec 20, 2023
1 parent 5dc0e6b commit d8f0fa7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
24 changes: 15 additions & 9 deletions lib/c.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,31 +479,37 @@ int fclose(FILE *stream)
return 0;
}

/* Read a byte from file descriptor. So the return value is either in the range
* of 0 to 127 for the character, or -1 on the end of file. */
int fgetc(FILE *stream)
{
char buf;
int r = __syscall(__syscall_read, stream, &buf, 1);
if (r <= 0)
int buf = 0, r = __syscall(__syscall_read, stream, &buf, 1);
if (r < 1)
return -1;
return buf;
}

char *fgets(char *str, int n, FILE *stream)
{
int i = 0;
do {
char c = fgetc(stream);
if (c == -1 || c == 255) {
int i;
for (i = 0; i < n - 1; i++) {
int c = fgetc(stream);
if (c == -1) {
if (i == 0)
/* EOF on first char */
return NULL;
/* EOF in the middle */
str[i] = 0;
return str;
}
/* Not support casting yet. Simply assign it. */
str[i] = c;
i++;
} while (str[i - 1] != '\n');

if (c == '\n') {
str[i + 1] = 0;
return str;
}
}
str[i] = 0;
return str;
}
Expand Down
16 changes: 5 additions & 11 deletions src/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,17 +622,6 @@ token_t get_next_token()
return T_assign;
}

/* end of file */
/* "FIXME: The signedness of 'char' in the C programming language is indeed
* implementation-specific. For example, gcc for Arm treats 'char' as
* unsigned, while gcc for x86(-64) treats 'char' as signed. The warning
* below is raised in gcc for Arm:
* warning: comparison is always false due to limited range of data type
* [-Wtype-limits]
*/
if ((next_char == 0) || (next_char == -1))
return T_eof;

if (is_alnum(next_char)) {
char *alias;
int i = 0;
Expand Down Expand Up @@ -698,7 +687,12 @@ token_t get_next_token()
return get_next_token();
}

if (next_char == 0)
return T_eof;

error("Unrecognized input");

/* Unreachable, but we need an explicit return for non-void method. */
return T_eof;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/fib.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/snapshots/hello.json

Large diffs are not rendered by default.

0 comments on commit d8f0fa7

Please sign in to comment.