Resolve hisenbugs regarding GCC and -Os
This commit is contained in:
@ -45,14 +45,20 @@ int tz_next(Tokenizer *tz, Token *out) {
|
||||
size_t start = tz->pos;
|
||||
if (tz->str[start] == '"') {
|
||||
start++;
|
||||
do {
|
||||
tz->pos++;
|
||||
} while (tz->pos < tz->len && tz->str[tz->pos] != '"');
|
||||
tz->pos++;
|
||||
|
||||
out->ptr = tz->str + start;
|
||||
out->len = tz->pos - start - 1;
|
||||
|
||||
while (tz->pos < tz->len && tz->str[tz->pos] != '"') {
|
||||
tz->pos++;
|
||||
}
|
||||
|
||||
if (tz->pos >= tz->len) {
|
||||
out->ptr = tz->str + start;
|
||||
out->len = tz->len - start;
|
||||
tz->pos = tz->len;
|
||||
} else {
|
||||
out->ptr = tz->str + start;
|
||||
out->len = tz->pos - start;
|
||||
tz->pos++;
|
||||
}
|
||||
} else {
|
||||
while (tz->pos < tz->len && !string_chr_isspace(tz->str[tz->pos])) {
|
||||
tz->pos++;
|
||||
@ -65,6 +71,8 @@ int tz_next(Tokenizer *tz, Token *out) {
|
||||
}
|
||||
|
||||
void tz_classify(Tokenizer *tz) {
|
||||
const int tmpbufsz = 256;
|
||||
char *tmpbuf = dlmalloc(tmpbufsz);
|
||||
Token *tk = tz->tokens;
|
||||
while (tk) {
|
||||
if (tk->ptr[0] == '"' && tk->ptr[tk->len - 1] == '"') {
|
||||
@ -72,8 +80,8 @@ void tz_classify(Tokenizer *tz) {
|
||||
} else if (tk->ptr[0] == '@') {
|
||||
RtCmd *cmd = RTCMDS;
|
||||
while (cmd) {
|
||||
char tmpbuf[0xff] = {0};
|
||||
usnprintf(tmpbuf, sizeof(tmpbuf), "%.*s", (int)tk->len, tk->ptr);
|
||||
string_memset(tmpbuf, 0, tmpbufsz);
|
||||
usnprintf(tmpbuf, tmpbufsz, "%.*s", (int)tk->len, tk->ptr);
|
||||
if (string_strcmp(tmpbuf, cmd->cmdname) == 0) {
|
||||
tk->type = TOK_CMD;
|
||||
tk->cmd = cmd;
|
||||
@ -86,6 +94,7 @@ void tz_classify(Tokenizer *tz) {
|
||||
}
|
||||
tk = tk->next;
|
||||
}
|
||||
dlfree(tmpbuf);
|
||||
}
|
||||
|
||||
bool interp_readline(char *data, const char **bgptr, const char **endptr) {
|
||||
@ -147,15 +156,14 @@ bool interp_runstring(const char *string, InterpResult **res) {
|
||||
|
||||
rt_init();
|
||||
bool ok = true;
|
||||
|
||||
const char *bg, *end;
|
||||
interp_readline((char *)string, NULL, NULL);
|
||||
while (interp_readline(NULL, &bg, &end)) {
|
||||
size_t linelen = end - bg;
|
||||
Tokenizer tz = ZERO(&tz);
|
||||
Tokenizer tz = {0};
|
||||
tz_init(&tz, bg, linelen);
|
||||
|
||||
Token toktmp = ZERO(&toktmp);
|
||||
Token toktmp = {0};
|
||||
while (tz_next(&tz, &toktmp)) {
|
||||
Token *tok = dlmalloc(sizeof(*tok));
|
||||
tok->ptr = toktmp.ptr;
|
||||
@ -226,7 +234,6 @@ bool interp_runstring(const char *string, InterpResult **res) {
|
||||
|
||||
tz_free(&tz);
|
||||
}
|
||||
|
||||
done:
|
||||
return ok;
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ void do_file(char *filepath) {
|
||||
return;
|
||||
}
|
||||
|
||||
IoctlStat statbuf = ZERO(&statbuf);
|
||||
IoctlStat statbuf = {0};
|
||||
|
||||
ioctl(ioh, IOCTL_STAT, (uint64_t)&statbuf, 0, 0);
|
||||
if (statbuf.type != IOCTLSTAT_FILE) {
|
||||
|
Reference in New Issue
Block a user